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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,4ac6504560f5ef27 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-03-04 10:34:53 PST Path: archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!priapus.visi.com!orange.octanews.net!news-out.visi.com!petbe.visi.com!news.octanews.net!ash.uu.net!spool.news.uu.net!not-for-mail Date: Thu, 04 Mar 2004 13:34:41 -0500 From: Hyman Rosen User-Agent: Mozilla Thunderbird 0.5 (Windows/20040207) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Little Endian -> Big Endian (Ada95 / GNAT), Whats with floating point types? References: <4046b474_1@127.0.0.1> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Organization: KBC Financial Products Message-ID: <1078425292.143938@master.nyc.kbcfp.com> Cache-Post-Path: master.nyc.kbcfp.com!unknown@nightcrawler.nyc.kbcfp.com X-Cache: nntpcache 3.0.1 (see http://www.nntpcache.org/) NNTP-Posting-Host: 204.253.250.10 X-Trace: 1078425292 4910 204.253.250.10 Xref: archiver1.google.com comp.lang.ada:6061 Date: 2004-03-04T13:34:41-05:00 List-Id: Warren W. Gay VE3WWG wrote: > you can still represent a machine dependant number with > repeating decimal places There are no such numbers (on any common hardware). Whether it's IEEE, VAX, or any of a variety of other forms of hardware floating point representation, all of them can be written exactly as a finite length decimal number (not counting the bit patterns which do not represent numbers, of course). > If they don't do that, then the number has been rounded, > and thus does not quite represent the original value any > more ;-) (at a minimum, it is less faithful than it > could be). The OP was converting out of and back into the same representation. Given that, there are a pair of published algorithms which ensure completely faithful translation. One algoritm takes a decimal representation and converts it to the binary representation closest in value (coin flip for ties) and the other finds a shortest decimal representation for a binary number which will convert back exactly to that binary. The algorithms were both published in Proceedings of the ACM SIGPLAN '90 Conference on Programming Language Design and Implementation. G. L. Steele Jr. and J. L. White. How to Print Floating Point Numbers Accurately. W. D. Clinger How to Read Floating Point Numbers Accurately You can find free implementations of these algorithms in C at .