[fpc-devel] MinCurrency

2015-11-18 Thread 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.00E+00 , e=22
An unhandled exception occurred at $0042B180 :
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.

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] MinCurrency

2015-11-18 Thread LacaK




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.;
46   MaxCurrency: Currency =  922337203685477.;
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."
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.
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] MinCurrency

2015-11-18 Thread Jonas Maebe


LacaK wrote on Wed, 18 Nov 2015:

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.;
46   MaxCurrency: Currency =  922337203685477.;
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
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] MinCurrency

2015-11-18 Thread 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.00E+00 , e=22
An unhandled exception occurred at $0042B180 :
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.;
46   MaxCurrency: Currency =  922337203685477.;
47 {$endif}

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


-Laco.
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] MinCurrency

2015-11-18 Thread Jonas Maebe


LacaK wrote on Wed, 18 Nov 2015:



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.;
46   MaxCurrency: Currency =  922337203685477.;
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

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] MinCurrency

2015-11-18 Thread LacaK




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.

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel