UnitsNet icon indicating copy to clipboard operation
UnitsNet copied to clipboard

Allow infinity to be a valid number

Open tmilnthorp opened this issue 3 years ago • 8 comments

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?

tmilnthorp avatar Dec 01 '21 20:12 tmilnthorp

Looking for comments before I touch any code.

tmilnthorp avatar Dec 01 '21 20:12 tmilnthorp

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.

angularsen avatar Dec 01 '21 23:12 angularsen

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.

tmilnthorp avatar Dec 11 '21 13:12 tmilnthorp

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.

angularsen avatar Feb 13 '22 17:02 angularsen

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.

angularsen avatar Feb 13 '22 17:02 angularsen

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.

stale[bot] avatar Apr 16 '22 05:04 stale[bot]

Support for NaN and infinity is of significant interest. Its a major headache in our use of unitsnet.

seanspicer avatar Apr 21 '22 21:04 seanspicer

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.

angularsen avatar Apr 21 '22 21:04 angularsen

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.

stale[bot] avatar Aug 13 '22 05:08 stale[bot]