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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,8af7fe40dc0a55ae X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!z6g2000pre.googlegroups.com!not-for-mail From: sjw Newsgroups: comp.lang.ada Subject: Re: Restarting Tread: Why isn't this program working with Unchecked_Converstion Date: Fri, 16 Jan 2009 15:14:19 -0800 (PST) Organization: http://groups.google.com Message-ID: References: <83d19cd8-71ca-43c1-a3eb-05832290e565@r36g2000prf.googlegroups.com> <497076b5$1_1@glkas0286.greenlnk.net> NNTP-Posting-Host: 62.49.19.209 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1232147659 14022 127.0.0.1 (16 Jan 2009 23:14:19 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 16 Jan 2009 23:14:19 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: z6g2000pre.googlegroups.com; posting-host=62.49.19.209; posting-account=_RXWmAoAAADQS3ojtLFDmTNJCT0N2R4U User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-us) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:3401 Date: 2009-01-16T15:14:19-08:00 List-Id: On Jan 16, 12:18=A0pm, "Stuart" wrote: > "ChristopherL" wrote in message > > news:83d19cd8-71ca-43c1-a3eb-05832290e565@r36g2000prf.googlegroups.com... > > > I'm restarting the tread [How to put 200 into an integer sub-type of > > 16 bits (code included)] with a new subject because the last was too > > long! > > > > > I want to copy bits from an Ada float to a user defined short integer > > maintaining the same bit representation. (I'm sorry to reply to Stuart's post rather than OP's, but Google fails to show OP's posts at all! (perhaps there's a reason for that?)) Sorry to shout, Chris, but you CAN NOT FIT THE BITS OF A STANDARD FLOAT INTO ANYTHING SMALLER!!! IF YOU WANT THE SAME BIT REPRESENTATION YOU HAVE TO USE THE SAME NUMBER OF BITS!!! The following is another way of achieving unchecked conversion - the results on a little-endian machine (i686) are 2.00000E+02 -> 0 0 72 67 3.14159E+00 -> 219 15 73 64 with Ada.Numerics; with Ada.Text_IO; use Ada.Text_IO; with System.Storage_Elements; procedure Foo is F : Float; A : System.Storage_Elements.Storage_Array (1 .. 4); for A'Address use F'Address; pragma Import (Ada, A); -- prevent unwanted auto-initialisations function Image (B : System.Storage_Elements.Storage_Element) return String renames System.Storage_Elements.Storage_Element'Image; begin F :=3D 200.0; Put_Line (Float'Image (F) & " -> " & Image (A (1)) & " " & Image (A (2)) & " " & Image (A (3)) & " " & Image (A (4))); F :=3D Ada.Numerics.Pi; Put_Line (Float'Image (F) & " -> " & Image (A (1)) & " " & Image (A (2)) & " " & Image (A (3)) & " " & Image (A (4))); end Foo;