Skip to content

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

Merged
breakerzirconia merged 1 commit intomasterfrom
breakerzirconia/#124-avoid-accidental-flooring
Jun 20, 2022
Merged

[#124] [#130] Add lossless conversion to Fractional values#129
breakerzirconia merged 1 commit intomasterfrom
breakerzirconia/#124-avoid-accidental-flooring

Conversation

@breakerzirconia
Copy link
Contributor

@breakerzirconia breakerzirconia commented Jun 8, 2022

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

@breakerzirconia breakerzirconia requested a review from dcastro June 8, 2022 19:46
Copy link
Member

@dcastro dcastro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff, feel free to squash the fixups and merge ^^ 👍

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'.
@breakerzirconia breakerzirconia force-pushed the breakerzirconia/#124-avoid-accidental-flooring branch from 4f4c270 to 7bb28d5 Compare June 20, 2022 10:40
@breakerzirconia breakerzirconia merged commit 4d57fa4 into master Jun 20, 2022
@breakerzirconia breakerzirconia deleted the breakerzirconia/#124-avoid-accidental-flooring branch June 20, 2022 10:53
@dcastro dcastro changed the title [#124] Add lossless conversion to Fractional values [#124] [#130] Add lossless conversion to Fractional values Jun 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Order of type arguments Avoid accidental flooring when converting Time unit to numeric types

2 participants