你说的很有道理,
摘抄 man bc 的部分内容,
除法和取余,作了较详细的说明,但加和乘,都没说明 scale,估计假定用户知道吧。
Every expression has a scale.
This is derived from the scale of original numbers, the operation performed and in many cases, the value of the variable scale.
Legal values of the variable scale are 0 to the maximum number representable by a C integer.
expr + expr
The result of the expression is the sum of the two expressions.
expr * expr
The result of the expression is the product of the two expressions.
expr / expr
The result of the expression is the quotient of the two expressions.
The scale of the result is the value of the variable scale.
expr % expr
The result of the expression is the "remainder" and it is computed in the following way. To compute a%b, first a/b is computed to scale digits. That result is used to compute a-(a/b)*b to the scale of the maximum of scale+scale(b) and scale(a). If scale is set to zero and both expressions are integers this expression is the integer remainder function.
【 在 snoopyzhao 的大作中提到: 】
: scale 根本就不四舍五入,它就是直接截断
: 这个的计算过程是 1 - 0.058 = 0.942,而不是先算出来 0.94117 再四舍五入得 0.941
--
修改:eskimo1024 FROM 113.81.170.*
FROM 113.81.170.*