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,37e5589e32d8f03f,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!newsfeed.gamma.ru!Gamma.RU!npeer.de.kpn-eurorings.net!newsfeed.cw.net!cw.net!news-FFM2.ecrc.de!newsfeed01.sul.t-online.de!newsmm00.sul.t-online.de!t-online.de!news.t-online.com!not-for-mail From: Matthias Kretschmer Newsgroups: comp.lang.ada Subject: Floating-Point Numbers and Internal Representation Date: Sun, 4 Dec 2005 11:33:32 +0100 Organization: T-Online Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: news.t-online.com 1133692412 02 15100 IqHyJ2-1A75f041 051204 10:33:32 X-Complaints-To: usenet-abuse@t-online.de X-ID: S3OvYEZaZeBijxDCUSJOqypxpsyJYlS1yyZ0oW6rk+EWRChaN-shU- User-Agent: slrn/0.9.8.1 (NetBSD) Xref: g2news1.google.com comp.lang.ada:6733 Date: 2005-12-04T11:33:32+01:00 List-Id: Hello, I had a problem in one of my programs, that was caused by the internal representation of floating-point numbers in the fpu. Concrete: calculating the value of an optimum for some large number of objects, then in a second doing something with all optimal objects. The problem was, that when doing the calculation the second time, the compiler left the floating-point number in the fpu which had a higher precision than the representation I choosed, so comparing for equality returns always "False". The problem would be solved by some operation truncating the floating-point number to the precision I orginally wanted or used. I could of course put all the values in an array or list and then finding optimum and optimal objects, but I don't want to go this way. In C iirc I could use a volatile variable to ensure the compiler will put the value in and read from the variable before comparing, but to achieve something similiar (truncating the precision to that of the type used) in Ada? My current solution is to enhance precision to compiler maximum which seems to be the machine maximum. But I would like to know if there are any better solutions? -- Matthias Kretschmer