I am writing an (almost) IEEE 854 compliant floating point implementation in TeX (which only has support for 32-bit integers). This standard only specifies the result of +
, -
, *
, /
, comparison, remainder, and sqrt
: for those operations, the result should be identical to rounding the exact result to a representable number (according to the rounding mode).
I seem to recall that IEEE specifies that transcendental functions (sin
, exp
...) should yield faithful results (in the default round-to-nearest mode, they should output one of the two representable numbers surrounding the exact result). Computing the sine of small numbers is rather straightforward: shift by a multiple of 2*pi to obtain a number in the range [0,2*pi], then do some more work to reduce the range to [0,pi/4], and use a Taylor series.
Now assume that I want to compute sin(1e300). For that I would need to find 1e300 modulo 2*pi. That requires to know 300 (316?) decimals of pi, because with only 16 decimals, the result would have no significance whatsoever (in particular, it souldn't be faithful).
Is there a standard on what the result of sin(1e300)
and similar very large numbers should be?
What do other floating point implementations do?
There is no standard that requires faithful rounding of transcendental functions. IEEE-754 (2008) recommends, but does not require, that these functions be correctly rounded.
Most good math libraries strive to deliver faithfully rounded results over the entire range (yes, even for huge inputs to sin( )
and similarly hard cases). As you note, this requires that the library know somewhat more digits of π then there are digits in the largest representable number. This is called an "infinite-pi" argument reduction.
To the point that @spraff raises, good math libraries adopt the viewpoint that the inputs are infinitely precise (i.e., the function should behave as though the input is always represented accurately). One can debate whether or not this is a reasonable position, but thats the working assumption for essentially all good math libraries.
All that said, there are plenty of libraries that take the easy route and use a "finite-pi" reduction, which basically treats a function like sin( )
as though π were a representable finite number. It turns out that this doesn't really cause any trouble for most uses, and is certainly easier to implement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With