Difference among approximatelyEqual and essentiallyEqual in The art of computer programming

前端 未结 3 1281
南笙
南笙 2021-02-19 19:37

I get this code snippet from some where else. According to the webmaster, the code is picked from The art of computer programming by Knuth

Since I do not have a copy of

3条回答
  •  既然无缘
    2021-02-19 19:39

    approximatelyEqual gives whether the difference between a and b is smaller than the acceptable error (epsilon), determined by the larger of a or b. This means that the two values are "close enough", and we can say that they're approximately equal.

    essentiallyEqual gives whether the difference between a and b is smaller than the acceptable error (epsilon), determined by the smaller of a or b. This means that the values differ less than the acceptable difference in any calculation, so that perhaps they're not actually equal, but they're "essentially equal" (given the epsilon).

    This has applications in issues where we have data and "acceptable error" rates and such. This code just gives you an algorithmic definition of those terms.

提交回复
热议问题