Hi, could someone explain clearly what exactly Delphi does when I write "if a > b then", given that "var a, b: Extended"?
By trial and error I have found that it only checks the first 19 non-zero digits, e.g.
0.000...00001 > 0.0 is True for any number of zeros
98765432109876543220.0 > 98765432109876543210.0 is True (differ in the 19th digit)
98765432109876543211.0 > 98765432109876543210.0 is False (differ in the 20th digit)
The last one is sort of surprising result for me, because the difference is 1.0, which is quite a lot (in absolute terms).
Further, there is a plenty of recommendations everywhere and methods implemented in a plenty of packages, which try to do something like
Clearly, the relation that resulted False above, would now be True. So, what is better? Can IsAGreaterThanB result in any problems? What about time requirements and precision? Should PrecisionEpsilon be as above or simply 1E-20?
Is a similar rule of taking only the first 19 digits applied also in multiplication (subtraction etc.) or all possibly 4932 digits are being multiplied? (If the rest is ignored, then perhaps the function IsAGreaterThanB is useless...)
Why is it in Delphi Help written that the number of significant digits for Extended is 10-20 (while for other float types they only differ by 1, so I would expect 19-20 here)?
Can onyone provide me with the first ~20 digits of the smallest (negative) Extended number? Delphi Help says that number is -3.6 x 10^4951, but this is not enough if one wants to be precise.
And the last doubt. When I define
my Turbo Delphi shows in the Structure-Errors an error saying "Invalid real constant at line...", though it compiles OK. The constants are Extended by default. So why that warning?
Many thanks for any insightful answer.
By trial and error I have found that it only checks the first 19 non-zero digits, e.g.
0.000...00001 > 0.0 is True for any number of zeros
98765432109876543220.0 > 98765432109876543210.0 is True (differ in the 19th digit)
98765432109876543211.0 > 98765432109876543210.0 is False (differ in the 20th digit)
The last one is sort of surprising result for me, because the difference is 1.0, which is quite a lot (in absolute terms).
Further, there is a plenty of recommendations everywhere and methods implemented in a plenty of packages, which try to do something like
Code:
const PrecisionEpsilon = 3.36210314311209558E-4932;
function IsAGreaterThanB(a, b: Extended): Boolean;
begin
Result := ((a - b) > PrecisionEpsilon);
end;
Clearly, the relation that resulted False above, would now be True. So, what is better? Can IsAGreaterThanB result in any problems? What about time requirements and precision? Should PrecisionEpsilon be as above or simply 1E-20?
Is a similar rule of taking only the first 19 digits applied also in multiplication (subtraction etc.) or all possibly 4932 digits are being multiplied? (If the rest is ignored, then perhaps the function IsAGreaterThanB is useless...)
Why is it in Delphi Help written that the number of significant digits for Extended is 10-20 (while for other float types they only differ by 1, so I would expect 19-20 here)?
Can onyone provide me with the first ~20 digits of the smallest (negative) Extended number? Delphi Help says that number is -3.6 x 10^4951, but this is not enough if one wants to be precise.
And the last doubt. When I define
Code:
const MAXFLOATVALUE = 1.18973149535723103E+4932;
Many thanks for any insightful answer.