m4预处理器BC宏

时间:2014-06-16 17:31:18

标签: m4

相对于this question,我想定义该函数的BC m4宏:

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

注意:它只是处理bc的算术运算,例如:syscmd(bc <<< "scale=6; print 1.2*2") => 2.4

我猜是这样的:

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

但如何扩展BC参数中的其他变量,例如:

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

BC(ONEPOINTTWO*TWO)
=> 2.4

谢谢

1 个答案:

答案 0 :(得分:2)

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

然后:

BC(ONEPOINTTWO*TWO)
=> 2.4