serokell / o-clock

:hourglass: Type-safe time units in Haskell
Mozilla Public License 2.0
49 stars 6 forks source link

[#124] [#130] Add lossless conversion to Fractional values #129

Closed breakerzirconia closed 2 years ago

breakerzirconia commented 2 years ago

Problem: The function toNum transforms an object of the type Time timeunit to a value of the type that satisfies the Num constraint. However, the former object can contain a fractional value inside, which then needs to get floored before being converted to a Num value. This could lead to a possible loss of precision.

Solution: Create a separate function that converts the Time objects losslessly to a value of the type that satisfies a stricter constraint: Fractional. The lossless conversion can be done via fromRational.

Fixes #124 Fixes #130