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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,9b4538cfeb0c3576 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news1.google.com!goblin2!goblin1!goblin.stu.neva.ru!news2.euro.net!feeder.news-service.com!xlned.com!feeder5.xlned.com!feeder2.cambriumusenet.nl!feed.tweaknews.nl!87.79.20.105.MISMATCH!news.netcologne.de!ramfeed1.netcologne.de!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Float conversion Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <9e669a3b-1013-4bd1-b372-5f7dfa46d083@f42g2000yqn.googlegroups.com> <1q5zc0ais535h$.1jqwfxhj9cflc$.dlg@40tude.net> <4c519968$0$6893$9b4e6d93@newsspool2.arcor-online.net> <1d1txn4x3r5xn.1trm4gx9n87gm$.dlg@40tude.net> Date: Thu, 29 Jul 2010 21:15:02 +0200 Message-ID: <1jo4xj7cntwy1$.1ntf9smcka8vf$.dlg@40tude.net> NNTP-Posting-Date: 29 Jul 2010 21:14:59 CEST NNTP-Posting-Host: 5d726e97.newsspool2.arcor-online.net X-Trace: DXC=@Ye^mLK6;ak:i=48;n?Z:`A9EHlD;3Ycb4Fo<]lROoRa8kF On Thu, 29 Jul 2010 11:21:52 -0700 (PDT), Henrique wrote: > On Jul 29, 12:35�pm, "Dmitry A. Kazakov" > wrote: >> ------------------------ >> var1 9.99900024414063E+02 >> var4 9.99900085449219E+02 >> >> When rounded to 6 decimal digits both are same. But the underlying base >> binary type is longer than 6 digits. >> >> P.S. It is always useful to think of floating point numbers as intervals >> (which they are) rather than numbers. >> >> -- >> Regards, >> Dmitry A. Kazakovhttp://www.dmitry-kazakov.de > > As I declared the type with 6 digits, I expected that it would make > the comparison only for these digits (this would gave var4 = var1). No, the underlying base type is more or less free compiler choice. There are certain rules, which in essence guarantee you accuracy of the basic operations within the precision specified. > Do I always need to manually truncate the float number to the number > of desired digits before making a comparison of them?? You should never use equality or inequality for floating-point types. They do not have "physical" sense. As I said, floating-point numbers are intervals. Two non-zero length [independent] intervals are *always* unequal, even if their bounds are equal. > So what is the advantage of declaring it as "digits 6"? That the compiler guarantees you 6 decimal digits accuracy independently on whatever hardware you have. The idea behind of Ada numeric types is machine independence. You specify your requirements on the precision and range and the compiler either gives you what you wanted or else rejects the program. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de