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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,cb3f9900b9cf2da6 X-Google-Attributes: gid103376,public From: dewar@cs.nyu.edu (Robert Dewar) Subject: Re: Truncation of FLOAT values Date: 1996/04/19 Message-ID: #1/1 X-Deja-AN: 150463409 references: <4l6bjn$b96@cliffy.lfwc.lockheed.com> <4l8a6h$274@newsbf02.news.aol.com> organization: Courant Institute of Mathematical Sciences newsgroups: comp.lang.ada Date: 1996-04-19T00:00:00+00:00 List-Id: John Herro said "function Floor(X : in Float) return Integer is Answer : Integer := Integer(X); begin if Float(Answer) > X then Answer := Answer - 1; end if; return Answer; end Floor;" Although this will typically work, Ada semantics do not guarantee that it will work. X may not be a model number, suppose that in fact X is 1.99999999999999999999999999999999 representing a number that is less than the model number 2.0, but greater than the largest model number less than 2.0. Now answer will surely be 2 Float(Answer) is the model number 2.0 but since x is not a model number, it can be treated as though it were any number in its model interval, and in particular as 2.0, so that the test may yield false and the final restul returned is 2 instead of 1. You can actually imagine this happening with some scenarios of extended values being passed in registers. Floating-point semantics are very delicate :-)