Skip to content

Commit 64e94c9

Browse files
refactor: Simplify rounding function.
1 parent f07e109 commit 64e94c9

1 file changed

Lines changed: 3 additions & 12 deletions

File tree

entries/dcornelius/src/uChallengeCommon.pas

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ TChallengeCommon = class
3333
public
3434
constructor Create(const NewInputFilename: string);
3535
procedure ReadAndParseAllData(WeatherCityProcessor: TWeatherCityProc);
36-
function PascalRound(x: Double): Double;
36+
function PascalRound(const x: Double): Double;
3737
function SplitCityTemp(const StationLine: string; var CityName: string; var CityTemp: Integer): Boolean;
3838
property InputFilename: string read FInputFilename write FInputFilename;
3939
end;
@@ -62,18 +62,9 @@ constructor TChallengeCommon.Create(const NewInputFilename: string);
6262
raise EFileNotFoundException.Create(NewInputFilename + ' not found.');
6363
end;
6464

65-
function TChallengeCommon.PascalRound(x: Double): Double;
66-
var
67-
t: Double;
65+
function TChallengeCommon.PascalRound(const x: Double): Double;
6866
begin
69-
// round towards positive infinity
70-
t := Trunc(x);
71-
if (x < 0.0) and (t - x = 0.5) then
72-
Result := t
73-
else if Abs(x - t) >= 0.5 then
74-
Result := t + Sign(x)
75-
else
76-
Result := x;
67+
Result := Ceil(x * 10) / 10;
7768
end;
7869

7970
procedure TChallengeCommon.ReadAndParseAllData(WeatherCityProcessor: TWeatherCityProc);

0 commit comments

Comments
 (0)