Re: [fpc-devel] CompareValue

2007-03-04 Thread Vincent Snijders

[EMAIL PROTECTED] schreef:

Quoting Vincent Snijders <[EMAIL PROTECTED]>:


C Western schreef:

ð£ÔÒ ëÏÓÁÒÅ×ÓËÉÊ wrote:
In the math unit are the CompareValue functions only for signed 
integers. Why not for DWORD and QWORD?
I guess, that it's Delphi mimicing implementation (because it is 
Delphi-like).


And it can be tricky to distinguish signed and unsigned expression 
values.


Like,
a: qword;
a-1 --- ??? (anyone may know for sure that a-1>0 and want to subtract 
one)


I guess it's something like that.
If you check  you can 
see this bug in action - the fpcadds and math unit provide signed and 
unsigned versions of CompareValue, but the correct one is not always 
chosen.



What a lousy compiler we use! ;-)

Do you have a testprogram, so I can make a fpc bug report?


I think this is inherent in the language design, as it is too easy to convert
between signed and unsigned integers. For example should the call:

CompareValue(0,0)

use the signed or unsigned version?


But in this particular case, I did not use constants, but variables of 
the same type.


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


Re: [fpc-devel] CompareValue

2007-03-04 Thread mftq75
Quoting Vincent Snijders <[EMAIL PROTECTED]>:

> C Western schreef:
> > ð£ÔÒ ëÏÓÁÒÅ×ÓËÉÊ wrote:
> >>> In the math unit are the CompareValue functions only for signed 
> >>> integers. Why not for DWORD and QWORD?
> >>
> >> I guess, that it's Delphi mimicing implementation (because it is 
> >> Delphi-like).
> >>
> >> And it can be tricky to distinguish signed and unsigned expression 
> >> values.
> >>
> >> Like,
> >> a: qword;
> >> a-1 --- ??? (anyone may know for sure that a-1>0 and want to subtract 
> >> one)
> >>
> >> I guess it's something like that.
> > 
> > If you check  you can 
> > see this bug in action - the fpcadds and math unit provide signed and 
> > unsigned versions of CompareValue, but the correct one is not always 
> > chosen.
> > 
> 
> What a lousy compiler we use! ;-)
> 
> Do you have a testprogram, so I can make a fpc bug report?

I think this is inherent in the language design, as it is too easy to convert
between signed and unsigned integers. For example should the call:

CompareValue(0,0)

use the signed or unsigned version?

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


Re: [fpc-devel] CompareValue

2007-03-04 Thread Vincent Snijders

C Western schreef:

Пётр Косаревский wrote:
In the math unit are the CompareValue functions only for signed 
integers. Why not for DWORD and QWORD?


I guess, that it's Delphi mimicing implementation (because it is 
Delphi-like).


And it can be tricky to distinguish signed and unsigned expression 
values.


Like,
a: qword;
a-1 --- ??? (anyone may know for sure that a-1>0 and want to subtract 
one)


I guess it's something like that.


If you check  you can 
see this bug in action - the fpcadds and math unit provide signed and 
unsigned versions of CompareValue, but the correct one is not always 
chosen.




What a lousy compiler we use! ;-)

Do you have a testprogram, so I can make a fpc bug report?

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


Re: [fpc-devel] CompareValue

2007-03-03 Thread C Western

Пётр Косаревский wrote:
In the math unit are the CompareValue functions only for signed integers. Why not 
for DWORD and QWORD?


I guess, that it's Delphi mimicing implementation (because it is Delphi-like).

And it can be tricky to distinguish signed and unsigned expression values.

Like, 


a: qword;
a-1 --- ??? (anyone may know for sure that a-1>0 and want to subtract one)

I guess it's something like that.


If you check  you can 
see this bug in action - the fpcadds and math unit provide signed and 
unsigned versions of CompareValue, but the correct one is not always chosen.


Colin

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


Re: [fpc-devel] CompareValue

2007-03-02 Thread Пётр Косаревский
> In the math unit are the CompareValue functions only for signed integers. Why 
> not 
> for DWORD and QWORD?

I guess, that it's Delphi mimicing implementation (because it is Delphi-like).

And it can be tricky to distinguish signed and unsigned expression values.

Like, 

a: qword;
a-1 --- ??? (anyone may know for sure that a-1>0 and want to subtract one)

I guess it's something like that.
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


[fpc-devel] CompareValue

2007-03-02 Thread Vincent Snijders

Hi,

In the math unit are the CompareValue functions only for signed integers. Why not 
for DWORD and QWORD?


I tested with the program below.

For DWord is works correctly, presumely because the int64 overload is used.
For QWord without typecast the code doesn't compile, because the compile cannot 
choose the right overload. With typecasts it returns the wrong values.


The math unit also has these lines:
{ this causes more trouble than it solves
function Min(a, b: Cardinal): Cardinal;
function Max(a, b: Cardinal): Cardinal;
}
It doesn't tell what problems and why.


Vincent

===
program Project1;

{$mode objfpc}{$H+}

uses
  Classes, SysUtils, Math
  { add your units here };

var
  d1, d2: dword;
  q1, q2: qword;
begin
  d1 := $F000;
  d2 := 10;
  writeln('CompareValue (d1,d2): ', comparevalue(d1,d2));
  writeln('CompareValue (d2,d1): ', comparevalue(d2,d1));
  q1 := $F000;
  q2 := 10;
  writeln('CompareValue (q1,q2): ', comparevalue(int64(q1),int64(q2)));
  writeln('CompareValue (q2,q1): ', comparevalue(int64(q2),int64(q1)));
  readln;
end.
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel