[fpc-pascal] compare currency and double
jonas.maebe at elis.ugent.be
Sun Dec 7 16:07:59 CET 2014
On 07/12/14 15:44, Xiangrong Fang wrote:
> I have the following code:
> val: Currency;
> res: Double;
> val := 2345.67;
> res := 1e300;
> if val >= res then WriteLn('val >=res')
> else WriteLn('val < res');
> The program compile and runs correctly on Linux x64, and Win7 32bit, but
> failed (SIGFPE) on Win7 64bit.
That's because currency has a bigger range than double. On Linux x64 and
Windows 32 bit, the x87 fpu can be used, so the currency value can be
converted to an 80 bits extended value. The x87 and hence also its 80
bits extended type have been deprecated on Win64, so FPC doesn't use it
> Can I safely compare a Currency against a Double?
No. It generally also doesn't make sense, because the whole point of
using currency is to have an exact value without rounding errors, while
a double value by nature very often contains rounding errors.
More information about the fpc-pascal