[comp.sys.mac.programmer] 68881/Floating Point Math in Think C

sandell@ils.nwu.edu (Greg Sandell) (07/02/90)

I'm trying to get some consistent behavior out of math
operations when using the 68881 chip, and can't quite
figure out the pattern.

If you don't know, the following is a no-no when the 68881 is
involved.  printf() can't print out a double because a double
is 96 bits long now, rather than 80.

	double foo;
	foo = 123.456;
	printf("%lf", foo);	/* prints nonsense */

The solution:

	#include <math.h>
	#include <sane.h>
	double x96foo;
	extended80 x80foo; 
	x96foo = 123.456;
	x96tox80(&x96foo, &x80foo);  /* from the SANE library */
	printf("%lf", x80foo);	     /* this works */

Unfortunately, this is about all I know, and I got it from a
telephone call with tech support at Think C.  Somehow alot of
other rules change in math programming...I can't cast an 
extended80 to an int, for example.  Is there an introduction
to how this math works somewhere?  I'm trying to avoid buying
the $40. APPLE NUMERICS MANUAL, but if that's the only source...

Thanks in advance,
Greg Sandell
****************************************************************
* Greg Sandell (sandell@ils.nwu.edu)              Evanston, IL *
* Institute for the Learning Sciences, Northwestern University *
****************************************************************