Skip to content
Prev 52349 / 63421 Next

Different results for tan(pi/2) and tanpi(1/2)

If pi were stored and computed to infinite precision then yes we would
expect tan(pi/2) to be NaN, but computers in general and R
specifically don't store to infinite precision (some packages allow
arbitrary (but still finite) precision) and irrational numbers cannot
be stored exactly.  So you take the value of the built in variable pi,
which is close to the theoretical value, but not exactly equal, divide
it by 2 which could reduce the precision, then pass that number (which
is not equal to the actual irrational value where tan has a
discontinuity) to tan and tan returns its best estimate.

Using finite precision approximations to irrational and other numbers
that cannot be stored exactly can have all types of problems at and
near certain values, that is why there are many specific functions for
calculating in those regions.
On Fri, Sep 9, 2016 at 12:55 PM, Hans W Borchers <hwborchers at gmail.com> wrote: