Mail Archives: djgpp/1999/05/29/16:16:45
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 -