Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!pasteur!ames!sgi!key!perry From: perry@key.COM (Peter Kiehtreiber) Newsgroups: comp.sys.mac.programmer Subject: Re: IBM (Intel) Real Numbers Summary: Be careful with ASCII representations of floating-point numbers Keywords: IEEE floating-point, 8087, 68881 Message-ID: <361@key.COM> Date: 14 Feb 89 21:40:02 GMT References: <14486@cup.portal.com> <12194@dartvax.Dartmouth.EDU> <655@internal.Apple.COM> Reply-To: perry@arkon.key.COM (Perry The Cynic) Organization: Key Computer Laboratories, Fremont Lines: 30 In article <655@internal.Apple.COM> SIAC@applelink.apple.com (Eric Ulevik) writes: > In article <14486@cup.portal.com> Greg_Mark_Finnegan@cup.portal.com > writes: > >Has anyone ever tried to read a data file from an IBM PC > >that consisted of REAL (in the Pascal sense) numbers.> > > >Any help or code would be appreciated. > The simplest method (_if_ you can afford the disk space and CPU time) is > to re-read the pc data file into a pc program, and write it out as > ascii-format numbers (eg. "0.123E4"). This makes it a lot easier to > write a Mac program to read the data. Be careful with (decimal) text representations for floating-point numbers. Both the conversion to and from decimal text involves rounding and therefore inaccuracies, and the changes are (generally) not reversible. Unless you take special precautions, the numbers coming out at the other end are marginally different from the original. Both the 80[23]87 and 6888[12] coprocessors purport to conform to the IEEE floating-point standard. As such, the separation in exponent/mantissa, exponent biasing, NaN recognition etc. are the same. The only difference lies in bit (and byte) ordering, and certain details like silent/screaming NaN distinction. The text transmission method Eric mentions above is OK if the programs separate the numbers into exponent and mantissa, and read and write them as hexadecimal (or octal or whatever) text. (Decimal is of course also OK, but might not be as easy unless your compilers support (very) long integers). -- ------------------------------------------------------------------------ Perry The Cynic (Peter Kiehtreiber) perry@arkon.key.com ** What good signature isn't taken yet? ** ...!pacbell!key!perry