[fpc-pascal] Inconsistent results currency - extended ?
Bruno Krayenbuhl
kraybruno at bluewin.ch
Mon May 5 10:52:11 CEST 2014
Lacak :
1 - XP difference between 2.6.4 and 2.7.1 on same machine
writeln('extended=', e);
extended=-9.22337203685477580811E+0014 <== HERE
calls str_real in real2str.inc that is in the course of beeing modified in 2.7.1. If your compare the source code, you will see it has changed and is in fact work in progress, at least in my OLD downloaded version of FPC2.7.1.
If it is still like that with the latest developpment 2.7.1, maybe some knowlegable developper should have a look at it.
2 - Difference between 2.6.4 on Win98 and WinXP.
I suspect that these 2 are on different computers and thus do not have exactly the same floating point unit. Line
e:=c; uses the FPU to convert from Currency to Extended. Schematically, Extended stores values Sign*2^exponent*Mantissa. (See http://en.wikipedia.org/wiki/Extended_precision for more info) That means, for example, that 0.1 cannot be EXACTLY stored in an Extended thus, depending on the FPU, they might be converted to a slightly different representation.
2b - Quote : It seems, that FPC on Win98 incorrectly stores currency constant.
No. And the proof is that :
writeln('currency=', c);
writeln('string=', currtostr(c));
do actualy writeln the correct result. Both use at some point currtostr(c). What currtostr(c) does is expand the Int64(c) to a decimal string and then insert the point in the position(length-4).
As long as there are no divisions and no Overflow, Currency will give correct and exact decimal results in all +, -,* computations, it is a simple Int64 that is converted (see 2b) to a decimal representation when displayed. I have used Currency in Quick Basic Compiler in the old days, then in Delphi applications for accounting purposes (with some customized roundings / convertions to Float when needed) and never had complaints from users.
Regards, Bruno
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20140505/12aa46a2/attachment.html>
More information about the fpc-pascal
mailing list