# Re: no tests for trigonometric functions? need help / hints how to adapt tests for gnumeric 'long' version,

• From: John Denker <jsd av8n com>
• To: gnumeric-list gnome org
• Subject: Re: no tests for trigonometric functions? need help / hints how to adapt tests for gnumeric 'long' version,
• Date: Sun, 29 May 2022 08:30:59 -0700

```On 5/29/22 12:59 AM, Steven D'Aprano wrote:

```
```tan() produces an output that is grossly
nonlinear (indeed wildly non-monotonic).
```
```
```
```Why is that? The mathematical function tan is monotonically increasing
in the range [0, π/2). Shouldn't tan() be the same?
```
```
I am considering tan() *near* π/2 ... not just "less
than" π/2. See the graph:
https://av8n.com/computer/img48/trig-function-accuracy.png

cot() is well behaved in this whole neighborhood but
tan() is singular.

To anticipate the obvious follow-up question: Why am
I considering the whole neighborhood?

That's because when dealing with roundoff errors, one
should prepare for *both* possibilities: some things
will get rounded down while other things will get
rounded up.

In our case, the IEEE double representation of π/2
gets rounded down ... but the representation of π
gets rounded up.
tan(pi/2)       1.63312e+16
cot(pi)         -8.16562e+15

Tangential remark:
This is why you should test for infinity using isinf(x)
rather than checking for bitwise equality x==inf. That's
because tanpi(0.5) could be +inf or it could just as
well be -inf.

Specifically:
(inf == -inf) is false but isinf(-inf) is true.
```

• References: