Feature request: overload floor and ceil for Int64
Original Reporter info from Mantis: Bart @flyingsheep
-
Reporter name: Bart Broersma
Original Reporter info from Mantis: Bart @flyingsheep
- Reporter name: Bart Broersma
Description:
Currently floor() and ceil() from math unit always return integer.
It would be nice to have overloaded functions that can return an Int64.
Steps to reproduce:
function Floor64(D: Double): Int64;
begin
Result := Trunc(D);
if Frac(D) < 0 then
Result := Result - 1;
end;
function Ceil64(D : Double) : Int64;
begin
Result := Trunc(D);
if Frac(D) > 0 then
Result := Result + 1;
end;
var
F64, C64, T64: Int64;
F32, C32, T32: Integer;
D: Double;
begin
DefaultFormatSettings.DecimalSeparator := '.';
D := 11111111111.111100000000000;
{$R+} //actually makes no diffrence in results
T64 := Trunc(D);
F64 := Math.Floor(D);
C64 := Math.Ceil(D);
writeln('Using standard math functions');
writeln('D = ',D:22:22);
writeln('Trunc(D) = ',T64:11 ,' [',IntToHex(T64,16),']');
writeln('Floor(D) = ',F64:11 ,' [',IntToHex(F64,16),']');
writeln('Ceil(D) = ',C64:11 ,' [',IntToHex(C64,16),']');
writeln;
T64 := Trunc(D);
F64 := Floor64(D);
C64 := Ceil64(D);
writeln('Using overloaded versions for Int64');
writeln('D = ',D:22:22);
writeln('Trunc(D) = ',T64:11 ,' [',IntToHex(T64,16),']');
writeln('Floor(D) = ',F64:11 ,' [',IntToHex(F64,16),']');
writeln('Ceil(D) = ',C64:11 ,' [',IntToHex(C64,16),']');
writeln;
end;
Using standard math functions
D = 11111111111.111100000000000
Trunc(D) = 11111111111 [00000002964619C7]
Floor(D) = -1773790777 [FFFFFFFF964619C7]
Ceil(D) = -1773790776 [FFFFFFFF964619C8]
Using overloaded versions for Int64
D = 11111111111.111100000000000
Trunc(D) = 11111111111 [00000002964619C7]
Floor(D) = 11111111111 [00000002964619C7]
Ceil(D) = 11111111112 [00000002964619C8]
Mantis conversion info:
- Mantis ID: 28370
- OS: Window
- OS Build: Win7
- Platform: i386
- Version: 2.6.4
- Fixed in version: 3.1.1
- Fixed in revision: 32766 (#88957c62)
- Target version: 3.0.2