[fpc-devel] FormatFloat bug
Michael Van Canneyt
michael at freepascal.org
Wed May 30 11:10:21 CEST 2007
On Wed, 30 May 2007, Graeme Geldenhuys wrote:
> On 5/29/07, Michael Van Canneyt <michael at freepascal.org> wrote:
> > If I remember correctly:
> > Bookkeepers rounding as implemented by the Intel processors.
> > No own routines are used. It's left up to the processor.
> I thought FormatFloat() uses Common Rounding and FormatCurr() uses
> Bankers Rounding. This would make more sense, and I believe Delphi
> has this behavior.
Not that I know of. As far as I know, it's left up to the CPU.
But it's been a long time since I looked at this, so I might
be wrong. This is in the delphi docs:
function Round(X: Extended): Int64;
In Delphi, the Round function rounds a real-type value to an integer-type value.
X is a real-type expression. Round returns an Int64 value that is the value of X
rounded to the nearest whole number. If X is exactly halfway between two whole
numbers, the result is always the even number. This method of rounding is often
called "Banker’s Rounding".
If the rounded value of X is not within the Int64 range, a runtime error is
generated, which can be handled using the EInvalidOp exception.
Note: The behavior of Round can be affected by the Set8087CW procedure or SetRoundMode function.
And that's all that can be found. So from this I conclude it's up to the CPU,
and furthermore you cannot assume anything about it since the behaviour
of the CPU is programmable with the abovementioned procedures.
(which are obviously not portable, because they are Intel specific...)
More information about the fpc-devel