From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,4ac6504560f5ef27 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-03-04 03:55:31 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!central.cox.net!east.cox.net!filt01.cox.net!peer01.cox.net!cox.net!bigfeed.bellsouth.net!bignumb.bellsouth.net!news.bellsouth.net!bignews4.bellsouth.net.POSTED!84c79386!not-for-mail From: "David C. Hoos" Newsgroups: comp.lang.ada References: <4046b474_1@127.0.0.1> Subject: Re: Little Endian -> Big Endian (Ada95 / GNAT),Whats with floating point types? MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-13" Content-Transfer-Encoding: 8bit X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Message-ID: X-Trace: npbhgpngjbkmjfegdbdpiflmbcekedmfhojhikkbagflhcbommnkllebkcamagnahfoimeeijbfebhjgfgodbdgdaflagfconjdbldlgloieccbjlihjobgnalgpgobfhnegmefoldlnedpfcnpdjnlfiihalnbd NNTP-Posting-Date: Thu, 04 Mar 2004 06:53:44 EST Date: Thu, 4 Mar 2004 05:55:20 -0600 Xref: archiver1.google.com comp.lang.ada:6052 Date: 2004-03-04T05:55:20-06:00 List-Id: wrote in message news:4046b474_1@127.0.0.1... > Joachim Schr�er wrote: > > > A short question: > > > > It's not so simple with floating point types, just swapping bytes, or is > > it? One has to swap all the bits or? > > Interfaces.IEEE_Float_32 has 1 bit sign, 23 bit mantissa and 8 bit > > exponent, Interfaces.IEEE_Float_64 has 1 bit sign, 52 bit mantissa and 11 > > bit exponent when I remember correctly. > > > > > > Achim > > That's not easy because floats are really machine dependant. That's not a > simple endianess question. > > The universal solution for this is to store your floating point number in > ASCII in a string and then store the string. That takes more place, but > there is no portability problems since in every case, a float converted to > a string always from left to right. Then it's even possible to use the > number using a different format or precision... > There's certainly more than one "universal solution." One supplied by the compiler manufacturer is likely to be a good one, viz.: If you use Stream IO to write the data, then you can take advantage of the solution the GNAT folks created for Distributed Systems (Annex E of the Ada Language Reference Manual). This solution is embodied in the glade supplement to gnat. For example, if you're using gnat-3.15p, the corresponding glade can be found at ftp://ftp.cs.nyu.edu/pub/gnat/3.15p/glade Then, replace the file s-stratt.adb in your standard gnat distribution with the one from the same version of glade, and re-compile and rebuild the library files (.a), and you have what you want. Now, as long as your types are declared the same on both platforms (with no representation clauses) you will have platform-independence. I'm not sure why GNAT didn't do this from the beginning -- perhaps because they didn't provide an implementation of the Distributed Systems Annex at the beginning. Also, there is a small performance penalty paid for shuffling bits around to achieve platform independence. Hope this helps.