r-quantities / units

Measurement units for R
https://r-quantities.github.io/units
172 stars 27 forks source link

`%%` doesn't work correctly due to rounding #364

Closed UchidaMizuki closed 4 months ago

UchidaMizuki commented 4 months ago

The behavior of %% provided by Ops.units() is different from that of base %%. Is this a expected behavior?

units::set_units(3, m) %% units::set_units(4, m)
#> -1 [m]
units::set_units(3 %% 4, m)
#> 3 [m]

Created on 2024-02-21 with reprex v2.1.0

This behavior seems to be caused by rounding in the following code. Shouldn't we use floor() instead of round() here? https://github.com/r-quantities/units/blob/928e883c07d29ed6382a483945dc4787ab9ede0f/R/arith.R#L103-L110