gunnarmorling / 1brc

1️⃣🐝🏎️ The One Billion Row Challenge -- A fun exploration of how quickly 1B rows from a text file can be aggregated with Java
https://www.morling.dev/blog/one-billion-row-challenge/
Apache License 2.0
5.69k stars 1.72k forks source link

Make the rounding rule match the baseline #746

Open edorfaus opened 2 months ago

edorfaus commented 2 months ago

In PR #392 a rule was added that rounding must be done by the IEEE 754 rule "towards positive infinity". This rule is also known as rounding up, or ceiling (it rounds 1.1 to 2).

However, the baseline implementation does not do this - instead, it rounds to nearest, with ties towards positive infinity.

The same PR adds an extra rounding step that I think improves the resilience against accumulated floating-point errors (by using knowledge about the input values), but does not actually change its rounding behavior otherwise.

I'm assuming that the current baseline behavior is intended, making the error be in the rule text (probably based on a simple misunderstanding of the standard). Therefore I propose a rule change to make the rules match the baseline implementation.

Since the other implementations are verified against the baseline output rather than directly against the rules, this avoids any need for code changes.

This PR also adds a few test cases to the rounding test, that I used to verify the expected rounding rules for both positive and negative numbers, without it being obscured by the floating-point inaccuracy. (Both the baseline and baseline_original_rounding implementations pass these tests, but code that uses any of the IEEE 754 rounding rules won't.)