You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+39-20Lines changed: 39 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -68,33 +68,51 @@ Submit your implementation and become part of the leader board!
68
68
69
69
## Rounding
70
70
71
-
Székely Balázs has provided code for rounding towards positive infinity per the original challenge.
72
-
This will be the official way to round the output values:
71
+
While I recognize that Székely's rounding code was a good effort, it was not simple and made a lot of people doubt it was even correct for negative temperatures.\
72
+
In a discussion with [Mr. Packman](https://pack.ac/) themselves, we came up with a simpler solution. They even added some _Unit Testing_:D.
73
+
74
+
This will be the official way to round the output values, so pick your poison:
73
75
```pas
74
-
function TBaseline.RoundEx(x: Double): Double;
76
+
function RoundEx(x: Double): Double; inline;
75
77
begin
76
-
Result := PascalRound(x*10.0)/10.0;
78
+
Result := Ceil(x * 10) / 10;
77
79
end;
78
80
79
-
function TBaseline.PascalRound(x: Double): Double;
81
+
function RoundExInteger(x: Double): Integer; inline;
82
+
begin
83
+
Result := Ceil(x * 10);
84
+
end;
85
+
86
+
function RoundExString(x: Double): String; inline;
80
87
var
81
-
t: Double;
88
+
V, Q, R: Integer;
82
89
begin
83
-
//round towards positive infinity
84
-
t := Trunc(x);
85
-
if (x < 0.0) and (t - x = 0.5) then
90
+
V := RoundExInteger(x);
91
+
if V < 0 then
86
92
begin
87
-
// Do nothing
93
+
Result := '-';
94
+
V := -V;
88
95
end
89
-
else if Abs(x - t) >= 0.5 then
90
-
begin
91
-
t := t + Math.Sign(x);
92
-
end;
93
-
94
-
if t = 0.0 then
95
-
Result := 0.0
96
96
else
97
-
Result := t;
97
+
Result := '';
98
+
Q := V div 10;
99
+
R := V - (Q * 10);
100
+
Result := IntToStr(Q) + '.' + IntToStr(R);
101
+
end;
102
+
103
+
procedure Test;
104
+
var
105
+
F: Double;
106
+
begin
107
+
for F in [10.01, 10.04, -10.01, -10.0, 0, -0, -0.01] do
> We are still waiting for the Delphi version to be completed in order for us to have an official `SHA256` hash for the output.
150
168
>
151
-
> Until then, this is the current one: `db3d79d31b50daa8c03a1e4f2025029cb137f9971aa04129d8bca004795ae524`
169
+
> Until then, this is the current one: `4256d19d3e134d79cc6f160d428a1d859ce961167bd01ca528daca8705163910`
152
170
> There's also an archived version of the [baseline output](./data/baseline.output.gz)
153
171
154
172
## Differences From Original
@@ -211,7 +229,8 @@ I'd like to thank [@paweld](https://github.com/paweld) for taking us from my mis
211
229
I'd like to thank [@mobius](https://github.com/mobius1qwe) for taking the time to provide the Delphi version of the generator.\
212
230
I'd like to thank [@dtpfl](https://github.com/dtpfl) for his invaluable work on maintaining the `README.md` file up to date with everything.\
213
231
I'd like to thank Székely Balázs for providing many patches to make everything compliant with the original challenge.\
214
-
I'd like to thank [@corneliusdavid](https://github.com/corneliusdavid) for giving some of the information files a once over and making things more legible and clear.
232
+
I'd like to thank [@corneliusdavid](https://github.com/corneliusdavid) for giving some of the information files a once over and making things more legible and clear.\
233
+
I'd like to thank Mr. **Pack**man, aka O, for clearing the fog around the rounding issues.
215
234
216
235
## Links
217
236
The original repository: https://github.com/gunnarmorling/1brc\
0 commit comments