Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!cs.utexas.edu!tut.cis.ohio-state.edu!ucsd!hub!castor!stoms From: stoms@castor.ncgia.ucsb.edu (David Stoms) Newsgroups: comp.sys.mac.programmer Subject: Re: Mixing Sane And 881 Message-ID: <4258@hub.UUCP> Date: 10 Mar 90 21:28:50 GMT References: <629.25F2006D@blkcat.fidonet.org> <25f44316.711e@polyslo.CalPoly.EDU> Sender: news@hub.UUCP Reply-To: stoms@castor.ncgia.ucsb.edu (David Stoms) Distribution: na Organization: U. C. Santa Barbara, Geography Department Lines: 38 In article <25f44316.711e@polyslo.CalPoly.EDU> rcfische@polyslo.CalPoly.EDU (Raymond C. Fischer) writes: > >In article <629.25F2006D@blkcat.fidonet.org> Ken.Knight@f421.n109.z1.fidonet.org (Ken Knight) writes: >>Can anyone tell me how to mix code so that it will be able to take best >>advantage of the math system available. That is, if an FPU (881/2) is >>available to use it; otherwise use SANE; or if the user wants to use >wanted to, you could test for the 68882 and branch to the appropriate >version of the routine, but this is generally nasty business. Just >one of the problems is that 68882 reals are a different format (and >different size) than SANE reals. Actually it isn't that bad. Your compilers can be set to use 80-bit or 96-bit extended numbers which are actually have identical precision. To convert between the two you have to know the format. The format works like this: 96-bit: 96- exponent -80- empty -63- mantissa -0 80-bit: 80- exponent -63- mantissa -0 To convert between the two just move the exponent around. It doesn't matter wants in the empty space of 96-bit reals. You can write a nice macro to do this in C. These two work in ThC 4.0: #define _96to80(ext); ((extended96*)&(ext))->zero = ((extended96*)&(ext))->exp; #define _80to96(ext); ((extended96*)&(ext))->exp = ((extended96*)&(ext))->zero; They should work no matter how big the compiler thinks the numbers are but if you want to pass an 80-bit real to a function and your compiler is set for 96-bit reals then you have to use a macro like this: #define passext80(ext) (*(extended*)&((extended96*)&(ext))->zero) Another dangerous pitfall is converting an 80-bit real to a 96-bit real without declaring your varible 96-bits. This can happen if your compiler is set to 80-bit real and you declare a standard extended. Disclamer: This doesn't nessesarily apply to compilers other than Think C 4.0.