Next: , Up: Examples   [Contents]


3.3 Floating-point Numbers

Floating-point numbers are most commonly used in binary64 format, a.k.a. double precision. Internally they are stored in the form ± m * 2 ^ e with some integral mantissa m and exponent e. Most decimal fractions can only be stored approximately in this format.

The intervaltotext function can be used to output the approximate value up to the last decimal digit.

intervaltotext (infsup (0.1), "[.55g]")
  ⇒ ans = [0.1000000000000000055511151231257827021181583404541015625]

It can be seen that 0.1 is converted into the most accurate floating-point number. In this case that value is greater than 0.1. The next lower value can be seen after producing an interval enclosure around 0.1 with the nearest floating-point numbers in each direction.

intervaltotext (infsup ("0.1"), "[.55g]")
  ⇒ ans =
    [0.09999999999999999167332731531132594682276248931884765625,
     0.1000000000000000055511151231257827021181583404541015625]

The error of this approximation can be examined with the @infsup/wid function.

wid (infsup ("0.1"))
  ⇒ ans =    1.3878e-17

With the @infsup/nextout function an interval can be enlarged in each direction up to the next floating-point number. Around zero the distance towards the next floating point number is very small, but gets bigger for numbers of higher magnitude.

wid (nextout (infsup ([0, 1, 1e10, 1e100])))
  ⇒ ans =

       9.8813e-324    3.3307e-16    3.8147e-06    3.8853e+84