m4 preprocessor BC macro

◇◆丶佛笑我妖孽 提交于 2019-12-13 01:08:19

问题


Relative to this question, I'd like to define a BC m4 macro of that function:

syscmd(bc <<< "scale=6; print ARITHMETIC_OPERATION_STRING")

NB: It just process an arithmetic operation with bc, for ex: syscmd(bc <<< "scale=6; print 1.2*2") => 2.4

I guess something like:

define(`BC', syscmd(bc <<< "scale=6; print $1"))

but how to expand other variables in BC argument, eg:

define(`ONEPOINTTWO', `1.2')
define(`TWO', `2')

BC(ONEPOINTTWO*TWO)
=> 2.4

Thank you


回答1:


define(`BC', `syscmd(echo "scale=6; print $1" | bc)')

then:

BC(ONEPOINTTWO*TWO)
=> 2.4


来源:https://stackoverflow.com/questions/24249104/m4-preprocessor-bc-macro

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!