[BUG] Float>>tan

Andres Valloud sqrmax at prodigy.net
Wed Aug 22 23:42:30 UTC 2001


Hi.

> The Float>>tan implementation is written as "^self sin / self cos".
> In this case, "self cos" should have evaluated to zero and we
> should have got a division by zero.

Well yes, if self was exactly pi/2.  But floats are fractions hence you
cannot represent pi/2 exactly. Therefore I suspect that Float halfPi cos
will not be exactly zero.

Float halfPi cos <alt-p> 1.224606353822377e-16

Exactly.  And for the same reason, Float halfPi sin should not be
exactly 1...

Float halfPi sin <alt-p> 1.0
Float halfPi sin hex <alt-p> '3FF0000000000000'

Surprise!  Well, then I guess it has something to do the fact that the
derivative of sin is 0 at pi/2 (changes slowly so the difference in the
value of sin does not show up in floats) while the derivative of cos is
-1 at pi/2 (and therefore the difference in the value of cos does show
up).

This would mean that if p is the closest float approximation to pi/2,
then

* the float representation of 1 - sin(pi/2 + (pi/2 - p)) is zero because
this value is too small to represent in a float.

* the float representation of cos(pi/2 + (pi/2 - p)) is not zero because
this value is large enough to represent in a float.

Either that or the FPU is to blame.

Andres.




More information about the Squeak-dev mailing list