我在做:
echo "scale=2; sqrt( (-9.522 - -9.522)**2 + (-17.145 - -17.145)**2 + (-2.689 - -2.689)**2 )" | bc
Run Code Online (Sandbox Code Playgroud)
我得到:
(standard_in) 1: syntax error
(standard_in) 1: syntax error
(standard_in) 1: syntax error
Run Code Online (Sandbox Code Playgroud)
我不明白发生了什么。
请问,有什么建议吗?
乘方运算符中的bc是^不是**。来自man bc:
Run Code Online (Sandbox Code Playgroud)expr ^ expr The result of the expression is the value of the first raised to the second. The second expression must be an integer.
前任。
$ echo "scale=2; sqrt(2)^2" | bc
1.98
Run Code Online (Sandbox Code Playgroud)