Home > Back-end >  Delphi CompareValue compare the size of the problem
Delphi CompareValue compare the size of the problem

Time:09-25

Use Math CompareValue compare size appeared confused condition, under the guidance of Daniel want to know.
Debugging code is as follows:
Procedure TForm1. Btn1Click (Sender: TObject);
Var
VD, vE: Extended;
A, b, c, d: Double;
The begin
A:=100.99;
B:=50;
C:=10;
D:=30.99;
VD:=Abs (a - b - c - d);
VE:=10;
If CompareValue (vD, vE) & lt;> 1 then
ShowMessage (" 11 ");
end;
Here CompareValue (vD, vE) of the comparison results, I think should be 0 (equal to the return value is zero). The results of the return value is 1
Comparevalue (vD, 10) of the comparison results is 1, I don't think it should be caused by inconsistent argument types,
If it is CompareValue (vE, 10) comparison, the result is 0. The abs set into type Double the return value of vD,
CompareValue (vD, 10) is zero, the result of the also is normal,
Excuse me, why would beg absolute value after Extended more problems?

CodePudding user response:

Var
VD, vE,
A, b, c, d: Double;
Res: Boolean;
The begin
A:=100.99;
B:=50;
C:=10;
D:=30.99;
VD:=a - b - c - d;
VE: d=20.99;
Res:=SameValue (vD, vE);
If Res then
ShowMessage (" 11 ");

The original code, the DVD for double, vE as an Integer, should be inconsistent type
This is just a personal opinion
Code instead of the above, when d participate in operation, can come True on
CompareValue is also called SameValue
In general, to compare the two values is consistent, both values should participate in the operation, and comparison

CodePudding user response:

The function CompareValue (const. A, B: Integer) : TValueRelationship; The phrase ";
The function CompareValue (const. A, B: Int64) : TValueRelationship; The phrase ";
The function CompareValue (const. A, B: Single; Epsilon: Single=0) : TValueRelationship; The phrase ";
The function CompareValue (const. A, B: Double; Epsilon: Double=0) : TValueRelationship; The phrase ";
The function CompareValue (const. A, B: Extended; Epsilon: Extended=0) : TValueRelationship; The phrase ";

Compare A, B two variables, the relationship between if A B, the return value is 1; Among them A, B can only Integer, Int64, Single, Double, Extended expression,

  • Related