UnitsNet
UnitsNet copied to clipboard
Allow infinity to be a valid number
Is your feature request related to a problem? Please describe.
We would like to be able to indicate things such as perfect conductivity or perfectly insulated objects. This requires double.PositiveInfinity
to be accepted to unit constructors.
Describe the solution you'd like Remove the guard check for infinity.
Describe alternatives you've considered
We have considered using double.MaxValue
(which is our interim solution), however it is more accurate to use infinity.
Note this is a breaking behavior change. Should this be only considered for v5?
Looking for comments before I touch any code.
I think the main argument for not supporting NaN and Infinity, is that decimal does not support it. So it would be inconsistent across different quantities.
I would counter that as completely different underlying types, forcing them into consistent behavior is overly constrictive. Much like some of the arguments for equality, programmers know the underlying type and expect to use them.
I would recommend splitting the guard class into a double and decimal version.
I see your point, but I do think that very few consumers of UnitsNet know anything about the whole double vs decimal dilemma we are currently at. So I do think it would catch some people off guard.
In #982 , I would like to revisit the quantities using decimal
, whether they can be changed to double
.
A lot of the precision problems went away 1-2 years ago when we introuced Unit
as part of the representation, and for units that are particularly large/smal we can consider adding direct conversion functions to some of the other units to maybe overcome the issue.
If we can get all quantities onto double, then I would be more onboard with supporting NaN and Infinity.
I just think it is not a good experience if some quantities happily accept NaN and others throw an exception, for no intuitive reason.
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.
Support for NaN and infinity is of significant interest. Its a major headache in our use of unitsnet.
I think it might be more natural to support NaN and Infinity after this is merged: https://github.com/angularsen/UnitsNet/pull/1074
This way, double
and decimal
will correctly be used on the public properties instead of forcing double
everywhere.
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.