Unexpected choice of overloaded function to call involving Single and Double
Original Reporter info from Mantis: mftq75
-
Reporter name: C Western
Original Reporter info from Mantis: mftq75
- Reporter name: C Western
Description:
function Max(a, b: Double): Double; overload;
begin
WriteLn('Double');
if a > b then Result := a else Result := b;
end;
function Max(a, b: Single): Single; overload;
begin
WriteLn('Single');
if a > b then Result := a else Result := b;
end;
var
v1: Double;
v2: Single;
v3: Integer;
begin
v1 := Pi;
v2 := 0;
WriteLn(v1);
WriteLn(Max(v1,0));
WriteLn(Max(v1,0.0));
WriteLn(Max(v1,v2));
WriteLn(Max(v1,v3));
end.
Prints:
3.1415926535897931E+000
Single
3.141592741E+00
Double
3.1415926535897931E+000
Double
3.1415926535897931E+000
Single
3.141592741E+00
Max(Single,Single) is called in two cases in preference to Max(Double,Double). This implies precision is lost in two of the cases
Steps to reproduce:
Compile and run the pro9gram above.
Additional information:
Delphi prints "Double" on all 4 calls. This has been discussed in the fpc-pascal mailing list.
Mantis conversion info:
- Mantis ID: 33939
- OS: linux
- Platform: x86_64
- Version: 3.1.1
- Monitored by: » alank@shermanloan.com (Alan Krause), » @CuriousKit (J. Gareth Moreton)