981377660LMT / ts

ts学习
6 stars 1 forks source link

QuoRem 和 DivMod 的区别 #586

Open 981377660LMT opened 2 months ago

981377660LMT commented 2 months ago

https://studygolang.com/articles/31142 image image

981377660LMT commented 2 months ago

https://stackoverflow.com/questions/339719/when-is-the-difference-between-quotrem-and-divmod-useful

981377660LMT commented 2 months ago
  1. quot是向零截断的整数除法,而div的结果向负无穷大截断。
    Prelude> (-12) `quot` 5
    -2
    Prelude> (-12) `div` 5
    -3

    向下截断除法(不是向 0 方向——向负无穷大方向),以便余数始终为非负数

981377660LMT commented 2 months ago

前端有一个用来做数字格式化的库numerify.js,支持用户自定义Math.floor,就是为了解决使用quot除还是div除的问题

981377660LMT commented 2 months ago

go的bigInt也有两种除法 image