zoukankan      html  css  js  c++  java
  • 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:Windowssystem32>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:Windowssystem32>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:Windowssystem32>

    vim的修改

     

     

     

     

  • 相关阅读:
    P3368 【模板】树状数组 2
    P3374 【模板】树状数组 1
    BZOJ 2654
    BZOJ 1016
    BZOJ 4870
    BZOJ 4868
    BZOJ 1503
    P3379 【模板】最近公共祖先(LCA)
    雅礼2017国庆1-1
    使用 CefSharp 网页显示问题
  • 原文地址:https://www.cnblogs.com/itzxy/p/9542820.html
Copyright © 2011-2022 走看看