-
Notifications
You must be signed in to change notification settings - Fork 383
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
Convert Power to double #1195
Convert Power to double #1195
Conversation
Fails in json tests. Unsure what to do here. |
3 tests failing in CI it seems, all related to JSON converters. We probably handpicked decimal quantities for these tests, but we would have to create a new dummy quantity for testing purposes I guess if we want to keep the decimal JSON functionality around. It would also be important to verify that old serialized JSON for Power/BitRate/Information can still be deserialized after switching to double.
|
Yea the tests were just using Power to test decimal types. I just convered them to another existing decimal type. Def should add a test to test old output. |
95940df
to
23d1dd5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just a few minor suggestions.
Question; what do you think of also changing Information/BitRate from decimal to double?
On one hand, it is sort of weird to risk getting rounding errors like 8.00000001 bits. On the other hand, for all other units (kilobyte, etc) that are probably way more used, floating point is perhaps the expected value representation.
If we change all 3 quantities to double, we have the potential to clean up a LOT of QuantityValue complexity.
As much as it pains me, I think these actually do make sense as decimal by default. If we had generic support, it could be whatever the client wishes. |
I'm still not sure about Information, there's a lot of code just to avoid rounding errors on the unit Bit. For all other units Kilobyte etc, a non-integer value is probably expected anyway. Although, with #1206 it would probably read 5.299999999 kB instead of 5.3 kB in some cases. Come to think ofit, isn't Here tested with current implementation in CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
1000.2.ToString("g2").Dump(); // 1e+03
1000.2.ToString("n2").Dump(); // 1,000.20
Length.FromFeet(1000.2).ToString("s2").Dump(); // 1,000.2 ft
Length.FromFeet(1000.2).ToString("g2").Dump(); // 1,000.2 ft
Length.FromFeet(1000.2).ToString("n2").Dump(); // 1,000.20 ft
Length.FromFeet(1000.2).ToString("f2").Dump(); // 1000.20 ft
1000.234.ToString("g2").Dump(); // 1e+03
1000.234.ToString("n2").Dump(); // 1,000.23
Length.FromFeet(1000.234).ToString("s2").Dump(); // 1,000.23 ft
Length.FromFeet(1000.234).ToString("g2").Dump(); // 1,000.23 ft
Length.FromFeet(1000.234).ToString("n2").Dump(); // 1,000.23 ft
Length.FromFeet(1000.234).ToString("f2").Dump(); // 1000.23 ft |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I agree. Floating point error is a fact of life anyway. Some number can't even be represented and we still use them for computation everywhere. I don't think it's worth the complexity just for one unit. |
# Conflicts: # UnitsNet.Tests/CustomCode/PowerTests.cs # UnitsNet.Tests/GeneratedCode/TestsBase/PowerTestsBase.g.cs # UnitsNet/GeneratedCode/Quantities/Power.g.cs
No more decimal quantities support UnitSystem after removing Power. The remaining 2 decimal quantities Information and BitRate don't support UnitSystem, and we also plan to change them from decimal to double.
In PR #1195 @angularsen asks @tmilnthorp: > Question; what do you think of also changing Information/BitRate from decimal to double? > > On one hand, it is sort of weird to risk getting rounding errors like 8.00000001 bits. On the other hand, for all other units (kilobyte, etc) that are probably way more used, floating point is perhaps the expected value representation. > > If we change all 3 quantities to double, we have the potential to clean up a LOT of QuantityValue complexity. How about we continue that discussion here? 😄 This PR is pretty straightforward and mimics #1195, except that `Information` is used as the typical decimal quantity in some tests. Because there won't be any decimal quantities left if these PRs get merged, I removed those tests in anticipation of completely removing all decimal support. --------- Co-authored-by: Andreas Gullberg Larsen <andreas.larsen84@gmail.com>
### Changes - Remove `QuantityValue`, replaced with `double` - Remove `TValueType` from interfaces - Remove `IQuantity<TUnitType, out TValueType>` - Remove `IValueQuantity<out TValueType>` - Change `IQuantity<TSelf, TUnitType, out TValueType>` to `IQuantity<TSelf, TUnitType>` - Change `IArithmeticQuantity<TSelf, TUnitType, TValueType>` to `IArithmeticQuantity<TSelf, TUnitType>` ### Changes to UnitsNet.Serialiation.JsonNet - Deserializing previously serialized JSON for decimal quantities `Information`, `BitRate` and `Power` still work, but it now reads just `double Value` property and ignores `string ValueString` and `string ValueType` properties. This may lose precision compared to preserving the full `decimal` value, but `decimal` is no longer supported in v6. ### Background In #1195 @angularsen says: > If we change all 3 quantities to double, we have the potential to clean up a LOT of QuantityValue complexity. This made me wonder how deep that complexity goes so I decided to experiment, and this is the result. I must say some of these changes make me a bit sad. A lot of work and some very clever thinking went into supporting multiple numerical types, and I want to acknowledge that. 🙇 Also, I took it as far as possible but that might not be the best outcome, for example we might want to keep deserialization support. This just demonstrates a possible direction we could go in. --------- Co-authored-by: Andreas Gullberg Larsen <andreas.larsen84@gmail.com>
Fixes #1194