 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Florent Ouchet Guest
|
Posted: Sun May 01, 2005 6:25 pm Post subject: Very strange floatting point value on my P3M processor |
|
|
Hi,
I posted this article in this group because it seems to be an FPU
problem (not an RTL problem).
-9992.5 is an exact floatting point value. When it is stored inside a
single, there is absolutly no loss of precision (the dump of this value
is $C00C9C22).
A simple program to show the problem is:
var
Test: Single;
begin
SetPrecisionMode(pmExtended);
SetRoundMode(rmNearest);
Test := -9992.5;
ShowMessage(IntToStr(Round(Test)));
end;
It should show -9993 (mathematical rounding), but on my P3M @ 866MHz,
the result is -9992.
Has anyone the same behaviour ?
If so, it should be considerer as a processor bug.
Thanks in advance,
Florent
|
|
| Back to top |
|
 |
Avatar Zondertau Guest
|
Posted: Sun May 01, 2005 6:42 pm Post subject: Re: Very strange floatting point value on my P3M processor |
|
|
| Quote: | I posted this article in this group because it seems to be an FPU
problem (not an RTL problem).
-9992.5 is an exact floatting point value. When it is stored inside a
single, there is absolutly no loss of precision (the dump of this
value is $C00C9C22).
A simple program to show the problem is:
var
Test: Single;
begin
SetPrecisionMode(pmExtended);
SetRoundMode(rmNearest);
Test := -9992.5;
ShowMessage(IntToStr(Round(Test)));
end;
It should show -9993 (mathematical rounding), but on my P3M @ 866MHz,
the result is -9992.
Has anyone the same behaviour ?
If so, it should be considerer as a processor bug.
|
I'm getting the same result, and i'm glad i did because otherwise my
CPU would have been broken.
This behavior is consistent with the documentention (IA32 software
developer's manual volume 1, section 4.8.4 "rounding"). Rounding to
neanest means bankers rounding for IEEE 754.
<quote>
Table 4-8. Rounding Modes and Encoding of Rounding Control (RC) Field
Rounding Mode RC Description
Field
Setting
Round to nearest (even) 00B Rounded result is the closest to the
infinitely precise result. If two
values
are equally close, the result is the
even value (that is, the one with the
least-significant bit of zero). Default
</quote>
-9992.5 is equally close to -9993 and -9992. -9992 is even, so when
performing bankers rounding it is preferred.
|
|
| Back to top |
|
 |
John Herbster Guest
|
Posted: Sun May 01, 2005 6:55 pm Post subject: Re: Very strange floatting point value on my P3M processor |
|
|
"Florent Ouchet" <ouchet.florent (AT) laposte (DOT) net> wrote
| Quote: | I posted this article in this group because it seems to be an FPU
problem (not an RTL problem). ...
A simple program to show the problem is:
var Test: Single;
begin
SetPrecisionMode(pmExtended);
SetRoundMode(rmNearest);
Test := -9992.5; {is an exact floating point value}
ShowMessage(IntToStr(Round(Test)));
end;
It should show -9993 (mathematical rounding),
but on my P3M @ 866MHz, the result is -9992.
|
Florent,
The rmNearest sets the FPU for "bankers rounding",
which is, of course, in the case of halves, to the
nearest *even* whole number value.
I am sorry that the Delphi Help file didn't mention that.
Be sure that you restore the default value before you
exit your special calculations code. Ex:
try
... your special calcs ...
finally
Set8087CW($1332);
end;
Regards, JohnH
|
|
| Back to top |
|
 |
Florent Ouchet Guest
|
Posted: Sun May 01, 2005 6:57 pm Post subject: Re: Very strange floatting point value on my P3M processor |
|
|
| Quote: | I'm getting the same result, and i'm glad i did because otherwise my
CPU would have been broken.
This behavior is consistent with the documentention (IA32 software
developer's manual volume 1, section 4.8.4 "rounding"). Rounding to
neanest means bankers rounding for IEEE 754.
quote
Table 4-8. Rounding Modes and Encoding of Rounding Control (RC) Field
Rounding Mode RC Description
Field
Setting
Round to nearest (even) 00B Rounded result is the closest to the
infinitely precise result. If two
values
are equally close, the result is the
even value (that is, the one with the
least-significant bit of zero). Default
/quote
-9992.5 is equally close to -9993 and -9992. -9992 is even, so when
performing bankers rounding it is preferred.
|
You are right, I wrote this article too fast :(
This is a very strange rounding system.
Thanks for your help,
Florent
|
|
| Back to top |
|
 |
Avatar Zondertau Guest
|
Posted: Sun May 01, 2005 7:09 pm Post subject: Re: Very strange floatting point value on my P3M processor |
|
|
| Quote: | You are right, I wrote this article too fast :(
This is a very strange rounding system.
|
It's not that strange; the advantage is that the average of rounded
numbers can be expected to be the same as the average of the numbers
themselves. This is important for bankers.
To round to nearest with halves being rounded upwards add 0.5 to the
number and set rounding to downwards.
|
|
| Back to top |
|
 |
Florent Ouchet Guest
|
Posted: Sun May 01, 2005 7:12 pm Post subject: Re: Very strange floatting point value on my P3M processor |
|
|
Hi,
| Quote: | The rmNearest sets the FPU for "bankers rounding",
which is, of course, in the case of halves, to the
nearest *even* whole number value.
I am sorry that the Delphi Help file didn't mention that.
|
It is mentionned in the french version. I have no excuse for reporting
this non-bug :(
| Quote: | Be sure that you restore the default value before you
exit your special calculations code. Ex:
try
... your special calcs ...
finally
Set8087CW($1332);
end;
|
Thanks for your help,
I always have some problems with bankers ;)
Florent
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|