Re: [fpc-pascal] Currency constant wrongly stored in generated EXE ? was: Re: Inconsistent results currency - extended ?
Bruno Krayenbuhl wrote / napísal(a): I have absolutely no idea of how the compiler does translate Currency constant to code, sorry. May be it uses the FPU when translating from String representation to assembler value, but I have absolutely no idea where that would be done in the compiler. Anyway, it may be possible that the compiler uses StrToCurr or something similar. var cAsString:string; . . cAsString:=CurrToStr(c); c:=StrToCurr(cAsString). { == Check after here on W98 / XP and look for differences on value c. That uses an FPU instruction fistpll that look as causing For : c:=strtocurr('92233720368547'); writeln(c); // here I get CORRECT result: 9.22337203685470E+13 But as I wrote: c:=92233720368547; writeln(c); // here I get INCORRECT result: 9.223372036854699520E+13 But as I wrote it is not a problem of displaying currency value, it is problem that currency variable realy contains incorrect number, which is then correctly displayed ... ;-( -Laco. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Currency constant wrongly stored in generated EXE ? was: Re: Inconsistent results currency - extended ?
Bruno Krayenbuhl wrote / napísal(a): 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. Yes Win 98 is on PC with Intel Pentium 4 CPU and Win XP on PC with Intel Core 2 Duo CPU But lets look again at our simplified program: = var c: currency; i64: int64; begin c:=92233720368547; = Here I stop and let's look at assembler of c:=92233720368547 : -- 00401543 a1c0204100 mov0x4120c0,%eax // low 4 bytes; EAX=-859001088 resp. 0xaf00 = 3435966208 00401548 a300604100 mov%eax,0x416000 0040154D a1c4204100 mov0x4120c4,%eax // high 4 bytes; EAX=214748364 00401552 a304604100 mov%eax,0x416004 -- So currency value is: 2^32*214748364 + 3435966208 = 922337200249503744 + 3435966208 = 922337203685469952 Not as expected 92233720368547 ! (this is on Win 98 PC !, on Win XP PC are values in EAX correct 3435966256, 214748364) So constant 92233720368547 which is part of generated EXE (I think) is wrong parsed or interpreted or what and stored wrongly in output EXE file. But why it happens ? What part of compiler is responsible for parsing constants in source code and translating them to binary form in which is stored in output EXE file ? Does compiler links any external DLLs which probably may change FPU control word (precision or so) ? Does compiler first converts value to floating point representation ant then back to currency or ? Thanks -Laco. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Currency constant wrongly stored in generated EXE ? was: Re: Inconsistent results currency - extended ?
My point N°2 regarding potential FPU difference was only concerning instruction line e:=c; = I have absolutely no idea of how the compiler does translate Currency constant to code, sorry. May be it uses the FPU when translating from String representation to assembler value, but I have absolutely no idea where that would be done in the compiler. Anyway, it may be possible that the compiler uses StrToCurr or something similar. var cAsString:string; . . cAsString:=CurrToStr(c); c:=StrToCurr(cAsString). { == Check after here on W98 / XP and look for differences on value c. That uses an FPU instruction fistpll that look as causing some trouble to other projects (Non FPC) } . . Regards, Bruno Note : I'm interested to know what you discover since I like using Currency's var. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal