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-7-bit X-Google-Thread: 103376,febd9e55846c9556 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-03-05 12:16:46 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!kibo.news.demon.net!news.demon.co.uk!demon!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Endianness independance Date: 05 Mar 2003 20:15:27 +0000 Organization: Pushface Sender: simon@smaug.pushface.org Message-ID: References: <3E6633C7.8000503@cogeco.ca> NNTP-Posting-Host: pogner.demon.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: news.demon.co.uk 1046895405 3814 62.49.19.209 (5 Mar 2003 20:16:45 GMT) X-Complaints-To: abuse@demon.net NNTP-Posting-Date: Wed, 5 Mar 2003 20:16:45 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1 Xref: archiver1.google.com comp.lang.ada:34929 Date: 2003-03-05T20:15:27+00:00 List-Id: "Warren W. Gay VE3WWG" writes: > If you look carefully at GLADE, you will notice that all that is > being done there is "byte swapping". There is more to independent > network formats than that (it just happens to work with _most_ > modern platforms at the moment). I don't know what version of GLADE you are looking at, but the code for 3.15p does a lot more than this. I am no expert as to whether it achieves the purpose or not on eg a VAX (but I don't believe that GNAT supports VAXes anyway). This is reading a single-length Float from the net: function I_F (Stream : access RST) return Float is I : constant Precision := Single; E_Size : Integer renames Fields (I).E_Size; E_Bias : Integer renames Fields (I).E_Bias; E_Last : Integer renames Fields (I).E_Last; F_Size : Integer renames Fields (I).F_Size; F_Mask : SE renames Fields (I).F_Mask; E_Bytes : SEO renames Fields (I).E_Bytes; F_Bytes : SEO renames Fields (I).F_Bytes; E : Unsigned; P : Boolean; X : Float; S : SEA (1 .. F_L); L : SEO; begin Ada.Streams.Read (Stream.all, S, L); if L /= S'Last then raise Data_Error; end if; -- Extract Fraction, Exponent and Sign. X := Float (S (F_L + 1 - F_Bytes) and F_Mask); for N in F_L + 2 - F_Bytes .. F_L loop X := X * FB + Float (S (N)); end loop; X := Scaling (X, -F_Size); -- Float if BS <= S (1) then P := False; E := Unsigned (S (1) - BS); else P := True; E := Unsigned (S (1)); end if; for N in 2 .. E_Bytes loop E := E * BB + Unsigned (S (N)); end loop; E := Shift_Right (E, Integer (E_Bytes) * SU - E_Size - 1); -- Look for special cases. if X = 0.0 then -- Signed zeros. if E = 0 then if P then return Float'Copy_Sign (0.0, 1.0); else return Float'Copy_Sign (0.0, -1.0); end if; else -- Signed infinites. if E = Unsigned (E_Last) then if P then return Float'Safe_Last; else return Float'Safe_First; end if; end if; end if; end if; -- Denormalized float. if E = 0 then X := Scaling (X, 1 - E_Bias); -- Flaot -- Normalized float. else X := Scaling (X + 1.0, Integer (E) - E_Bias); -- Float end if; if P then X := Float'Copy_Sign (X, 1.0); else X := Float'Copy_Sign (X, -1.0); end if; return X; end I_F;