bc -l 对于 %取模计算出错

https://yq.aliyun.com/articles/279384

 

expr % expr
   The  result of the expression is the "remainder" and it is com‐
   puted in the following way.  To compute a%b, first a/b is  com‐
   puted 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.

# bc -l
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
1/3
.33333333333333333333
--//可以看出使用math 库,缺省scale=20.
--//而如果不使用-l参数scale=0.

--//这样如果在scale=20的情况,取模使用是这样.

12312324/1232
9993.76948051948051948051

12312324-9993.76948051948051948051*1232
.00000000000000001168

scale=2
12312324%1232
11.68

12312324/1232
9993.76
--//bc竟然没做四舍五入.

12312324-9993.76*1232
11.68

===========================

C:\Windows\system32>bc
bc 1.05
Copyright 1991, 1992, 1993, 1994, 1997, 1998 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
1/3
0

C:\Windows\system32>bc -l
bc 1.05
Copyright 1991, 1992, 1993, 1994, 1997, 1998 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
1/3
.33333333333333333333

(interrupt) use quit to exit.

C:\Windows\system32>

vim的修改

 

 

 

 

 

posted @ 2018-08-27 16:10  zxyblog  阅读(328)  评论(0编辑  收藏  举报