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=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Thread: 103376,91965a012526b259 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!proxad.net!usenet-fr.net!enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: "David C. Hoos" Newsgroups: comp.lang.ada Subject: Re: Float to String Date: Mon, 8 Nov 2004 14:18:16 -0600 Organization: Cuivre, Argent, Or Message-ID: References: NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Trace: melchior.cuivre.fr.eu.org 1099945146 99494 212.85.156.195 (8 Nov 2004 20:19:06 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Mon, 8 Nov 2004 20:19:06 +0000 (UTC) Cc: "comp.lang.ada@ada.eu.org" To: "Pascal Obry" Return-Path: X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Gateway to the comp.lang.ada Usenet newsgroup" List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: g2news1.google.com comp.lang.ada:6055 Date: 2004-11-08T14:18:16-06:00 The previous message had a spelling error which was helpfully inserted by the Micro$oft spell-checker. The word "representable" was "corrected" to "represent." This is closely-related to a problem I encountered something over ten years ago. The problem in that case was that values stored in an Oracle database when later extracted sometimes differed in the lsb. What makes the problem similar is that Oracle required the data to be stored in decimal format. The problem with that is that decimal numbers are not, in general, exactly representable in binary. E.g. the decimal number 0.1 is a non-terminating binary number. The good news is that since binary numbers in a machine per force have a finite length, they can all be exactly represent as decimal numbers. The bad news about this is that the Text_IO.Float_IO package implementations I have seen are not capable of outputting those exact representations, and we, therefore, were obliged to implement our own, in order to satisfy the requirements of our customer to have equivalence down to the last bit. For binary numbers having n bits following the binary point, n digits are required following the decimal point to exactly represent the fractional part of the value. Such exact representations will always terminate with the digit "5." For binary numbers having n bits preceding the binary point, the number of decimal digits required to exactly represent the whole- number part of the value is (n log2 (10)) + 1. I hope this helps. ----- Original Message ----- From: "Pascal Obry" Newsgroups: comp.lang.ada To: Sent: Monday, November 08, 2004 11:06 AM Subject: Float to String > > I was wondering if there is a way to save a float into a string and read it > back without loosing precision ? > > I tried something like: > > F_Str : String (1 .. Float'Base'Digits); > > Float_Text_IO.Put (F_Str, My_Float, Aft => Float'Base'Digits); > > But this is not enough... Ideas ? > > Thanks, > Pascal. > > -- > > --|------------------------------------------------------ > --| Pascal Obry Team-Ada Member > --| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE > --|------------------------------------------------------ > --| http://www.obry.org > --| "The best way to travel is by means of imagination" > --| > --| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595 > _______________________________________________ > comp.lang.ada mailing list > comp.lang.ada@ada-france.org > http://www.ada-france.org/mailman/listinfo/comp.lang.ada >