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=2.6 required=5.0 tests=BAYES_20,INVALID_DATE, MSGID_SHORT,REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!edcastle!ssj From: ssj@castle.ed.ac.uk (S Johal) Newsgroups: comp.lang.ada Subject: Truncation of FLOATS Message-ID: <1550@castle.ed.ac.uk> Date: 10 Jan 90 18:06:08 GMT Reply-To: ssj@castle.ed.ac.uk (S Johal) Organization: Edinburgh University Computing Service List-Id: Hello ADA experts, One of my colleagues has a problem which I hope somebody has an easy solution to. Basically he is after the whole number part of a floating point number. We found no way in ADA to directly implement it, so we tried something like: ROUNDED := INTEGER(FLOATING_NUMBER); if FLOATING_NUMBER - ROUNDED >= 0.0 then TRUNCATED_PART := ROUNDED; else TRUNCATED_PART := ROUNDED - 1; end if; examples: FLOATING_NUMBER ROUNDED TRUNCATED_PART 6.4 6 6 6.6 7 6 the problem is: 7.0 7 6 ??? when it should be 7 We have checked what 7.0 - 7.0 gives, and its not 0.0, which is the problem I suppose. My colleague knows about converting to a string and taking off the integer bit, but this is inefficient. Any ideas ? *-------------------------------------------*----------------------------* * Subindrao Johal, *++++++++++++++++++++++++++++* * SARI Project, * tel: 031 668 1550 x219 * * Department of Electrical Engineering, * fax: 031 662 4678 * * University of Edinburgh, * email: ssj@sari.ed.ac.uk * * The King's Buildings, Edinburgh EH9 3JL *++++++++++++++++++++++++++++* *------------------------------------------------------------------------*