www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/05/29/16:16:45

Message-ID: <37504A52.DA4C5283@gmx.de>
Date: Sat, 29 May 1999 22:13:07 +0200
From: Christian Hofrichter <ChristianHofrichter AT gmx DOT de>
X-Mailer: Mozilla 4.51 [de]C-CCK-MCD QXW03200 (Win95; I)
X-Accept-Language: de,en
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: how to round fp-numbers correctly ?
Reply-To: djgpp AT delorie DOT com

I want to round an fp-number to the nearest representable integer value.
The standard rounding methode simply leaves out the mantisse of an
fp-number (e.g 0.5 is rounded  to 0 not to 1). Adding 0.5 only works if
the fp-number is positive, otherwise I have to check if the fp-number is
negative and then would have to substract 0.5. This would waste too much
time. Changing the rounding methode with "_control87(RC_NEAR,MCW_RC);"
didn't work. I don't know why .So what can I do to solve this problem ?
This should not be too difficult because there are a lot of
fp-instructions which "push" and "round" an fp-number. Shall I use the
inline-assembler ?


Another problem is the limited precision. Let's say some fp-operations
should return 100.0 but return 99.9999998 due to precision problems. If
I must compare this value (e.g in a loop) to define an end-condition I
need a comparing methode which says that 99.9999998 is equal to 100.0
and aborts the loop. Is this possible ? Otherwise testing if the
variable is greater or equal to 100.0 would fail and the loop would be
continued.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019