chickadee » math » absolute-error

absolute-error x rprocedure
x
number
r
number

Usually computes (abs (- x r)) using exact rationals, but handles non-rational reals such as +inf.0 specially.

Examples:

> (absolute-error 1/2 1/2)
0
> (absolute-error 0.14285714285714285 1/7)
7.93016446160826e-18
> (absolute-error +inf.0 +inf.0)
0.0
> (absolute-error +inf.0 +nan.0)
+inf.0
> (absolute-error 1e-20 0.0)
1e-20
> (absolute-error (- 1.0 (fp 4999999/5000000)) 1/5000000)
5.751132903242251e-18