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=-0.4 required=5.0 tests=AC_FROM_MANY_DOTS,BAYES_00 autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,319c841368a8705a X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-07-08 11:19:08 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed1.cidera.com!Cidera!cyclone1.gnilink.net!spamfinder.gnilink.net!nwrddc01.gnilink.net.POSTED!53ab2750!not-for-mail From: "Frank J. Lhota" Newsgroups: comp.lang.ada References: Subject: Re: float problem X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700 Message-ID: Date: Mon, 08 Jul 2002 18:19:08 GMT NNTP-Posting-Host: 141.157.176.41 X-Complaints-To: abuse@verizon.net X-Trace: nwrddc01.gnilink.net 1026152348 141.157.176.41 (Mon, 08 Jul 2002 14:19:08 EDT) NNTP-Posting-Date: Mon, 08 Jul 2002 14:19:08 EDT Xref: archiver1.google.com comp.lang.ada:26945 Date: 2002-07-08T18:19:08+00:00 List-Id: > Thanks, I didn't know that procedure "put" rounds given number. I have > just started to learn Ada, but I was using Pascal (and a bit Delphi) > before, where there is no rounding in procedure "write". Of course there is, as there is with the output of floating point numbers in most languages. The internal representation of floating point numbers are generally in binary format, whereas text output for humans should be in decimal. To represent the exact value stored in the internal representation would require dozens of decimal digits, most of which would be inaccurate due to roundoff errors. In every programming language I know of, the default is to display only as many decimal digits as can be expected to be accurate. The number is rounded to this reasonable number of decimal digits. For 32 bit IEEE floating numbers, one cannot guarantee that more than 6 decimal digits are accurate. That is why the default format for outputting such numbers only displays 6 decimal digits (1 before the decimal point, 5 after the decimal point) > BTW: is it possible to disable the rounding in "put"? Maybe with some > global boolean variable or someting (maybe a pragma). One way to see more decimal digits would be to increase the value of My_Float_Io.Default_Aft, e.g. My_Float_Io.Default_Aft := 6; This will change the default Aft for all calls to My_Float_Io.Put. As an alternative, I would recommend that in the call to Put for f, specify the AFT parameter and make it something larger than Float'Aft, e.g. put(f, Aft => 6); When I did this in your test program, the problem is shown rather clearly: -1.000000E+00 -1 -9.000000E-01 -1 -8.000000E-01 -1 -6.999999E-01 -1 -5.999999E-01 -1 -4.999999E-01 0 -1