Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2015-11

MinCurrency

6 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

LacaK
Hi,
When I run this on Win32 (FPC 2.6.4):
==============================================
var
     c: currency;
     e: integer;
begin
   c:=0;
   Val('-922337203685477.5808',c,e);
   Writeln('c=',c,' , e=',e);
   Writeln(StrToCurr('-922337203685477,5808'));
end.
==============================================

I get "correct" results:
------------------------------------------------------------------------- c=-9.223372036854775808E+14 , e=0
-9.223372036854775808E+14
-------------------------------------------------------------------------

But when I recompile for Win64 I get:
------------------------------------------------------------------------- c= 0.000000000000000000E+00 , e=22
An unhandled exception occurred at $000000000042B180 : EConvertError : "-922337203685477,5808" is an invalid float -------------------------------------------------------------------------

As per documentation: http://www.freepascal.org/docs-html/ref/refsu6.html -922337203685477.5808 is in range of Currency data type But in sysstrh.inc is conditional definition of MinCurrency, but none is -922337203685477.5808

What is right behavior ?
Thanks
-Laco.

Reply by email

LacaK
to LacaK
Show quoted text 36 lines
Hi, When I run this on Win32 (FPC 2.6.4): ============================================== var c: currency; e: integer; begin c:=0; Val('-922337203685477.5808',c,e); Writeln('c=',c,' , e=',e); Writeln(StrToCurr('-922337203685477,5808')); end. ============================================== I get "correct" results: ------------------------------------------------------------------------- c=-9.223372036854775808E+14 , e=0 -9.223372036854775808E+14 ------------------------------------------------------------------------- But when I recompile for Win64 I get: ------------------------------------------------------------------------- c= 0.000000000000000000E+00 , e=22 An unhandled exception occurred at $000000000042B180 : EConvertError : "-922337203685477,5808" is an invalid float ------------------------------------------------------------------------- As per documentation: http://www.freepascal.org/docs-html/ref/refsu6.html -922337203685477.5808 is in range of Currency data type But in sysstrh.inc is conditional definition of MinCurrency, but none is -922337203685477.5808 What is right behavior ? Thanks -Laco.

There is also related bug report:
http://bugs.freepascal.org/view.php?id=28737

And look at part of code in rtl/objpas/sysutils/sysstrh.inc:

41     {$if defined(FPC_HAS_TYPE_EXTENDED) or
defined(FPC_HAS_TYPE_FLOAT128)}
42       MinCurrency: Currency = -922337203685477.5807;
43       MaxCurrency: Currency =  922337203685477.5807;
44     {$else}
45       MinCurrency: Currency = -922337203685477.0000;
46       MaxCurrency: Currency =  922337203685477.0000;
47     {$endif}

Why is for case not defined(FPC_HAS_TYPE_EXTENDED), MinCurrency defined as is ?

-Laco.

Reply by email

Jonas Maebe
to LacaK

LacaK wrote on Wed, 18 Nov 2015:

Show quoted text 15 lines
There is also related bug report: http://bugs.freepascal.org/view.php?id=28737 And look at part of code in rtl/objpas/sysutils/sysstrh.inc: 41 {$if defined(FPC_HAS_TYPE_EXTENDED) or defined(FPC_HAS_TYPE_FLOAT128)} 42 MinCurrency: Currency = -922337203685477.5807; 43 MaxCurrency: Currency = 922337203685477.5807; 44 {$else} 45 MinCurrency: Currency = -922337203685477.0000; 46 MaxCurrency: Currency = 922337203685477.0000; 47 {$endif} Why is for case not defined(FPC_HAS_TYPE_EXTENDED), MinCurrency defined as is ?

I think that on those targets, some currency handling is still (or was?) implemented via the double type (instead of fixed point using int64), and double does not have enough precision to represent 922337203685477.5807.

Jonas

Reply by email

LacaK
to Jonas Maebe
Show quoted text 21 lines
> There is also related bug report: > http://bugs.freepascal.org/view.php?id=28737 > > And look at part of code in rtl/objpas/sysutils/sysstrh.inc: > > 41 {$if defined(FPC_HAS_TYPE_EXTENDED) or > defined(FPC_HAS_TYPE_FLOAT128)} > 42 MinCurrency: Currency = -922337203685477.5807; > 43 MaxCurrency: Currency = 922337203685477.5807; > 44 {$else} > 45 MinCurrency: Currency = -922337203685477.0000; > 46 MaxCurrency: Currency = 922337203685477.0000; > 47 {$endif} > > Why is for case not defined(FPC_HAS_TYPE_EXTENDED), MinCurrency > defined as is ? I think that on those targets, some currency handling is still (or was?) implemented via the double type (instead of fixed point using int64),

Is there way how to check current status?
If there is still need for conditional definition ? (if I look at occurences of MinCurrency in RTL source code, I think, that it can be adjusted ... in other words what is risk of changing MinCurrency and MaxCurrency constants ... IMO is better if they will have same value on all platforms, which supports Int64)

Because for example on Win64/x86_64 target, there is not defined FPC_HAS_TYPE_EXTENDED, so I get "truncated values" " -922337203685477.0000"
Oposed to Win32/i386, where I get
"-922337203685477.5807"

And secondly why is MinCurrency "-922337203685477.5807" and not "-922337203685477.5808"
(see mentioned bug report)

-Laco.

Reply by email

Jonas Maebe
to LacaK

LacaK wrote on Wed, 18 Nov 2015:

Show quoted text 23 lines
> >> There is also related bug report: >> http://bugs.freepascal.org/view.php?id=28737 >> >> And look at part of code in rtl/objpas/sysutils/sysstrh.inc: >> >> 41 {$if defined(FPC_HAS_TYPE_EXTENDED) or >> defined(FPC_HAS_TYPE_FLOAT128)} >> 42 MinCurrency: Currency = -922337203685477.5807; >> 43 MaxCurrency: Currency = 922337203685477.5807; >> 44 {$else} >> 45 MinCurrency: Currency = -922337203685477.0000; >> 46 MaxCurrency: Currency = 922337203685477.0000; >> 47 {$endif} >> >> Why is for case not defined(FPC_HAS_TYPE_EXTENDED), MinCurrency >> defined as is ? > > I think that on those targets, some currency handling is still (or > was?) implemented via the double type (instead of fixed point using > int64), Is there way how to check current status? If there is still need for conditional definition ?

You can just try to compile a test program with those constants and writing them. I think the problem is actually in the compiler itself. The constant is parsed independently of any specified type and therefore is parsed as a floating point constant. If the compiler is running on a platform that does not support the 80 bit extended type, the constant will be truncated at that point.

Changing the compiler to take the "currency" into account and parsing the number differently in that case would result in differences between

   const
     MinCurrency: Currency = -922337203685477.5807;

and

   const
     MinCurrencyConst = -922337203685477.5807;
     MinCurrency: Currency = MinCurrencySymbolicConst;

That is even worse, because then code becomes unpredictable.

Because for example on Win64/x86_64 target, there is not defined FPC_HAS_TYPE_EXTENDED, so I get "truncated values"

FPC_HAS_TYPE_EXTENDED is undefined on most platforms. It's only a very small minority that has it, but of course those are the most used ones.

And secondly why is MinCurrency "-922337203685477.5807" and not "-922337203685477.5808" (see mentioned bug report)

I don't know.

Jonas

Reply by email

LacaK
to Jonas Maebe
Show quoted text 13 lines
> Because for example on Win64/x86_64 target, there is not defined > FPC_HAS_TYPE_EXTENDED, so I get "truncated values" FPC_HAS_TYPE_EXTENDED is undefined on most platforms. It's only a very small minority that has it, but of course those are the most used ones. > And secondly why is MinCurrency "-922337203685477.5807" and not > "-922337203685477.5808" > (see mentioned bug report) I don't know.

Beside this I have found that, "-922337203685477.5808" is not supported by StrToCurr() and Val(), so I reported bug about this: http://bugs.freepascal.org/view.php?id=29037

-Laco.

Reply by email