-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update rounding code #246
update rounding code #246
Conversation
probably you want to keep the old methods for backwards compability? |
Codecov Report
@@ Coverage Diff @@
## master #246 +/- ##
==========================================
+ Coverage 77.72% 78.02% +0.29%
==========================================
Files 15 15
Lines 1037 1051 +14
==========================================
+ Hits 806 820 +14
Misses 231 231
Continue to review full report at Codecov.
|
* Convert REQUIRE to Project.toml using the gen_project.jl script * Add version 1.2 to CI * Modernize tweak script a bit
REQUIRE -> Project.toml; CI tweaks
Thanks, I agree a 1.0 update is useful, but I don't think rounding to significant digits is well defined for dimensionful quantities. It seems like things work if the units differ by powers of ten, but otherwise, the operation is not invariant under a change of units. Using your branch:
For some context, this kind of operation was first prohibited after #78. There was some discussion on making safe methods of |
I think the two-argument form of #207 is reasonable, but I do wonder whether the inch-vs-km example is related to units as such. That is, given
it's not surprising that the following versions using
To the extent that these kind of functions are used for display of data to humans, I find this completely reasonable behavior. On the other hand, surprises like #78 are no good. |
I think the issue with
is rather promotion of rounded quantities than rounding to significant digits itself. promote_rule(x::RoundedQuantity,y::Any) = error("Rounded quantities cannot be promoted due to loss of precision") or something like that. |
@c42f I get what you're saying and I agree there are usability compromises that must be made eventually. But in your example, you are passing |
To be clear, I'm not so much arguing for the changes in this PR as trying to understand the shape or the problem better by thinking out loud ;-) The point I was trying to make is that rounding is inherently dependent on the numerical representation because it's defined by finding the closest representable number in the base 10 positional numeral system with a given number of significant digits. Choose a different radix or numeral system and the set of representable numbers isn't even the same. The choice of representation in inch vs km gives a different lattice of numbers for the rounding operation, in some ways not dissimiiar from changing the radix. In any case thanks for explaining the larger design considerations surrounding this. I think your analogy to |
…Blacksmith/Unitful.jl into BeastyBlacksmith-rounding
so I did rebase and added the two and three argument forms as discussed in #249. |
This updates the rounding code to the post 1.0 era.
To me rounding to significant digits is also well defined for Quantities.
I need to adjust the tests.