Re: [fpc-pascal] Inconsistent results currency - extended ?
Thankyou very much for your effort!Yes I compile with same version FPC 2.6.4, but important point is, that on *Windows 98*!When I compile on Windows XP, I get same results as you for 2.6.4:CW=4978currency=-9.223372036854775808E+14currency=-9.22337203685470E+13extended=-9.2233720368547758E+0014string=-92233720368547,int64=-9223372036854775808double=-9.22337203685480E+017But slightly different for 2.7.1 (on same PC):CW=4978currency=-9.223372036854775808E+14currency=-9.22337203685470E+13extended=-9.22337203685477580811E+0014 == HEREstring=-92233720368547,int64=-9223372036854775808double=-9.2233720368547994E+017 == AND HERE(which does not must indicate error, because there is no exact floating point representation of given currency value)But my original question is why are different results for WinXP and Win98 with same compiler FPC 2.6.4 ? It seems, that FPC on Win98 incorrectly stores currency constant in generated EXE file, so varible "c" is initialised with wrong value ...(see my first email with results) Thanks -Laco. Tested with FPC 2.6.4 . LacaK are you sure you compile with the same version. To me everything looks fine. program test_Currency; {$mode objfpc}{$H+} uses {$IFDEF UNIX}{$IFDEF UseCThreads} cthreads, {$ENDIF}{$ENDIF} SysUtils; var s: string; c: currency; e: extended; d: double; i64: int64; begin i64:=1 shl 63; c:=PCurrency(@i64)^; // Minimum representable currency d:=-92233720368547; e:=c; i64:=PInt64(@c)^; writeln('CW=', Get8087cw()); writeln('currency=', c); c:=-92233720368547.; // LacaK currency writeln('currency=', c); writeln('extended=', e); writeln('string=', currtostr(c)); writeln('int64=', i64); writeln('double=', d); readln; end. Gives me : CW=4978 currency=-9.223372036854775808E+14 - Ok to me currency=-9.22337203685470E+13 - Ok to me extended=-9.2233720368547758E+0014 string=-92233720368547. - Ok to me int64=-9223372036854775808 double=-9.22337203685480E +017 BrunoK ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal-Laco. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Inconsistent results currency - extended ?
Tested with FPC 2.6.4 . LacaK are you sure you compile with the same version. To me everything looks fine. program test_Currency; {$mode objfpc}{$H+} uses {$IFDEF UNIX}{$IFDEF UseCThreads} cthreads, {$ENDIF}{$ENDIF} SysUtils; var s: string; c: currency; e: extended; d: double; i64: int64; begin i64:=1 shl 63; c:=PCurrency(@i64)^; // Minimum representable currency d:=-92233720368547; e:=c; i64:=PInt64(@c)^; writeln('CW=', Get8087cw()); writeln('currency=', c); c:=-92233720368547.; // LacaK currency writeln('currency=', c); writeln('extended=', e); writeln('string=', currtostr(c)); writeln('int64=', i64); writeln('double=', d); readln; end. Gives me : CW=4978 currency=-9.223372036854775808E+14 - Ok to me currency=-9.22337203685470E+13 - Ok to me extended=-9.2233720368547758E+0014 string=-92233720368547. - Ok to me int64=-9223372036854775808 double=-9.22337203685480E+017 BrunoK ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Inconsistent results currency - extended ?
Real values are not supposed to be exact. They are depending on the hardware and other stuff by design. currency is a funny beast :) -Michael ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Inconsistent results currency - extended ?
Your code does not even compile on my 2.6.4 installation (no Lazarus). Where does the currtostr function come from? Apparently from sysutils unit. How is it 'included' without any uses clause? I found no option that automatic add unit sysutils. Could you give us a source and a compilation command line that does not require Lazarus use? Pierre Muller -Message d'origine- De : fpc-pascal-boun...@lists.freepascal.org [mailto:fpc-pascal- boun...@lists.freepascal.org] De la part de LacaK Envoyé : mardi 29 avril 2014 10:23 À : FPC-Pascal users discussions Objet : [fpc-pascal] Inconsistent results currency - extended ? Hi, I catch strange behavior, which I can not understand ;-) I have 2 PC on both I have installed Lazarus 1.2.2 + FPC 2.6.4 (official release) 1st PC has Windows 98 2nd PC has Windows Vista (32 bit) I have this program: = var c: currency; e: extended; begin c:=-92233720368547; e:=c; writeln('CW=', Get8087cw(), ' currency=', c, ' extended=', e, ' string=', currtostr(c)); = When I compile on 1st PC (Win98) and run it on 1st or 2nd PC I get this result: CW=4978 currency=-9.223372036854699520E+13 extended=-9.2233720368546995E+0013 string=-92233720368546,9952 When I compile on 2nd PC (Win Vista) and run on 1st or 2nd PC I get (expected) result: CW=4978 currency=-9.22337203685470E+13 extended=-9.2233720368547000E+0013 string=-92233720368547 How is it possible? Is compiled code somehow affected by platform on which is compilation performed? Thanks -Laco. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Inconsistent results currency - extended ?
Your code does not even compile on my 2.6.4 installation (no Lazarus). Where does the currtostr function come from? Apparently from sysutils unit. Yes from SysUtils How is it 'included' without any uses clause? I found no option that automatic add unit sysutils. Could you give us a source and a compilation command line that does not require Lazarus use? Source code attached. Command line parameters: -MObjFPC -Scghi -O1 -Twin32 -Pi386 -g -gl -vewnhi -Filib\i386-win32 -Fu. -FUlib\i386-win32 -l (taken from Lazarus as I never have used only standalone compiler , without Lazarus IDE) = PROGRAM == program test_Currency; {$mode objfpc}{$H+} uses {$IFDEF UNIX}{$IFDEF UseCThreads} cthreads, {$ENDIF}{$ENDIF} SysUtils; var s: string; c: currency; e: extended; d: double; i64: int64; begin c:=-92233720368547; d:=-92233720368547; e:=c; i64:=PInt64(@c)^; writeln('CW=', Get8087cw()); writeln('currency=', c); writeln('extended=', e); writeln('string=', currtostr(c)); writeln('int64=', i64); writeln('double=', d); readln; end. When I compile on Win98 and run (it does not depend if it is ran on Win98 or XP or Vista) output is same: === OUTPUT 1 === CW=4978 currency=-9.223372036854699520E+13 extended=-9.2233720368546995E+0013 string=-92233720368546,9952 int64=-922337203685469952 double=-9.22337203685470E+013 It seems (based on i64 variable), that currency c is wrong initialised with -92233720368546.9952 On other side double is correct -92233720368547 When I compile on Win Vista and run (it does not depend if it is Win98 or XP or Vista) output is correct (as expected): === OUTPUT 2 CW=4978 currency=-9.22337203685470E+13 extended=-9.2233720368547000E+0013 string=-92233720368547 int64=-92233720368547 double=-9.22337203685470E+013 Thanks -Laco. Pierre Muller -Message d'origine- De : fpc-pascal-boun...@lists.freepascal.org [mailto:fpc-pascal- boun...@lists.freepascal.org] De la part de LacaK Envoyé : mardi 29 avril 2014 10:23 À : FPC-Pascal users discussions Objet : [fpc-pascal] Inconsistent results currency - extended ? Hi, I catch strange behavior, which I can not understand ;-) I have 2 PC on both I have installed Lazarus 1.2.2 + FPC 2.6.4 (official release) 1st PC has Windows 98 2nd PC has Windows Vista (32 bit) I have this program: = var c: currency; e: extended; begin c:=-92233720368547; e:=c; writeln('CW=', Get8087cw(), ' currency=', c, ' extended=', e, ' string=', currtostr(c)); = When I compile on 1st PC (Win98) and run it on 1st or 2nd PC I get this result: CW=4978 currency=-9.223372036854699520E+13 extended=-9.2233720368546995E+0013 string=-92233720368546,9952 When I compile on 2nd PC (Win Vista) and run on 1st or 2nd PC I get (expected) result: CW=4978 currency=-9.22337203685470E+13 extended=-9.2233720368547000E+0013 string=-92233720368547 How is it possible? Is compiled code somehow affected by platform on which is compilation performed? Thanks -Laco. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal program test_Currency; {$mode objfpc}{$H+} uses {$IFDEF UNIX}{$IFDEF UseCThreads} cthreads, {$ENDIF}{$ENDIF} SysUtils; var s: string; c: currency; e: extended; d: double; i64: int64; begin c:=currency(-92233720368547); d:=-92233720368547; e:=c; i64:=PInt64(@c)^; writeln('CW=', Get8087cw()); writeln('currency=', c); writeln('extended=', e); writeln('string=', currtostr(c)); writeln('int64=', i64); writeln('double=', d); readln; end. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal