[BUG] Float>>tan

Richard A. O'Keefe ok at atlas.otago.ac.nz
Thu Sep 6 02:56:34 UTC 2001


ajbn at cin.ufpe.br wrote:
	First of all, thanks for the technical explanation. 
	However, when I sent the message to squeak list I was thinking about one of the 
	potential squeak users: children.
	What will they think when they get these results? They can ask 'why does the 
	calculator available in the Windows environment, for Microsoft users, the same 
	where squeak is running, shows the correct result and squeak does not'.
	I ran the following commands in LCSI's MicroWorlds 2.05 english version (a well 
	known Logo-based programming enviroment for children) and I got the correct 
	answer for both sine and cosine of 90 degrees (although a wrong answer for 
	tangent as you can see):
	
Right there is your answer:  90 degrees.

If you measure angles in degrees (360 per cycle) or grads (400 per cycle)
or any measure where the number of "things" per complete cycle is an
exact rational number, you will be able to implement the trig functions
so that sin(), cos(), and tan() are exact for whole multiples of a
quarter cycle (which 90 degrees is).

HOWEVER, Squeak, like Fortran, C, and many other programming languages,
uses the standard mathematical unit for angles, where a cycle is 2 pi
radians.  Not only is pi not a rational number, it isn't even algebraic.

There are many many mathematical applications where the elegant
differential calculus properties of sine and cosine make the use of
cycle = 2 pi radians appropriate.

There are also applications where degrees, or grads, or my favourite
unit "1 cycle = 1 cycle" (where 90 degrees is 0.25 cycle) are appropriate.
Some Fortrans have handled this by providing SIND, COSD, and so on,
measuring angles in degrees.
Ada handles this by having
	function Sin(Angle: T, Cycle: T := Two_Pi) return T;
Sun's math library for C handles the problem by offering
    double sin(double r);	r in radians, uses infinite precision PI
    double sind(double d);	d in degrees
    double sinp(double r);	r in radians, but uses 64-bit precision PI
    double sinpi(double x);	x in half-cycles, returns sin(x*"true pi").

For the use of children, the simplest thing would be to whip out one's
trusty copy of Cody & Waite and code up sind(), cosd(), tand(), and so on.
(Or take one of the free C math libraries around and replace the range
reduction code.)  We _could_ make '90 degreesSin' "work".

(One of my favourite software engineering examples is the company which
had a Prolog compiler for the PC and a Prolog compiler for the Mac.  One
of the numerous incompatibilities between them was that one of them
measured angles in degrees and the other in radians...)




More information about the Squeak-dev mailing list