[fpc-devel] CompareValue

Vincent Snijders vsnijders at quicknet.nl
Fri Mar 2 14:01:36 CET 2007


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 := $F0000000;
   d2 := 10;
   writeln('CompareValue (d1,d2): ', comparevalue(d1,d2));
   writeln('CompareValue (d2,d1): ', comparevalue(d2,d1));
   q1 := $F000000000000000;
   q2 := 10;
   writeln('CompareValue (q1,q2): ', comparevalue(int64(q1),int64(q2)));
   writeln('CompareValue (q2,q1): ', comparevalue(int64(q2),int64(q1)));
   readln;
end.



More information about the fpc-devel mailing list