aurora-opensource / au

A C++14-compatible physical units library with no dependencies and a single-file delivery option. Emphasis on safety, accessibility, performance, and developer experience.
Apache License 2.0
329 stars 21 forks source link

Add integer-only versions of rounding functions #243

Open chiphogg opened 5 months ago

chiphogg commented 5 months ago

Right now, all of our rounding functions (the round, floor, and ceil families) are designed as "unit-aware" analogues of their standard library counterparts. This has the galling consequence that for people working with pure integer types, even though the final result will also be an integer, we need to take a detour through the floating point domain, because that is what the standard library functions do!

It feels like we could do way better, with an approach that Au makes possible which I've never seen before. We should be able to generate rounding functions that live purely inside of the integral domain. For example, we could generate a unit that is half the target unit, add "1" in this unit, and truncate the result. We'd need a bunch of test cases, but this could be really useful (especially for embedded code).