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,MAILING_LIST_MULTI, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,19805810c471a6af X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-11-07 19:50:05 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!fr.usenet-edu.net!usenet-edu.net!enst.fr!not-for-mail From: "Steven Deller" Newsgroups: comp.lang.ada Subject: RE: Decimals after the point Date: Thu, 7 Nov 2002 21:50:58 -0600 Organization: Smooth Sailing Sender: comp.lang.ada-admin@ada.eu.org Message-ID: Reply-To: comp.lang.ada@ada.eu.org NNTP-Posting-Host: marvin.enst.fr Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: avanie.enst.fr 1036727403 83869 137.194.161.2 (8 Nov 2002 03:50:03 GMT) X-Complaints-To: usenet@enst.fr NNTP-Posting-Date: Fri, 8 Nov 2002 03:50:03 +0000 (UTC) Return-Path: X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.2627 Importance: Normal In-Reply-To: <9qhcqa.bp3.ln@beastie.ix.netcom.com> X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300 X-RBL-Warning: This E-mail came from 67.251.129.13, a potential spam source listed in OSDUL. X-Note: This E-mail was scanned for spam. Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org X-Mailman-Version: 2.0.13 Precedence: bulk X-Reply-To: List-Unsubscribe: , List-Id: comp.lang.ada mail<->news gateway List-Post: List-Help: List-Subscribe: , Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org Xref: archiver1.google.com comp.lang.ada:30566 Date: 2002-11-07T21:50:58-06:00 Actually, for any binary representation, the only "2 decimal digit" values are those for which all bits after the first two fractional bits are zeroes, yielding all numbers that are some integer plus: 0.00, 0.25, 0.5, 0.75 The reason for this is that 2**N divides into 10**2 evenly only for N=0,1,2. So rather than test the decimal value, you only need to check the fractional part for *equality* with the above values. Normally equality testing with floating point values is not advisable, but it is called for here. I'll leave how to capture the fractional part of a floating point value and how to test it to you. Hint: Read the Ada manual attributes section. Regards, Steve Deller > -----Original Message----- > From: comp.lang.ada-admin@ada.eu.org > [mailto:comp.lang.ada-admin@ada.eu.org] On Behalf Of Dennis Lee Bieber > Sent: Wednesday, November 06, 2002 8:06 PM > To: comp.lang.ada@ada.eu.org > Subject: Re: Decimals after the point > > > Genevieve B. fed this fish to the penguins on Wednesday 06 November > 2002 03:01 pm: > > > Hi! > > > > For a project at university, there is a bonus that is to check for > > only 2 decimals after the point in a float. does anybody > have an idea? > > > > I have an idea of putting my float into a string instead and then > > check for the point...and then check for only 2 numbers after it... > > > Probably not valid -- after all, you could code the > float->string > write operation to only write two decimal places... Hence > you'd always > see just two decimals > > > However, the assignment is rather error-prone, due to > the problems of > decimal <> binary conversions. What was input as 1.40 may be > output as > 1.3999999. The assignment should properly specify what behavior is to