-
Notifications
You must be signed in to change notification settings - Fork 384
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
Special values (NaN, Inf+, Inf-) for doubles #1268
Comments
Hi, I guess the rationale is consistency. 3 quantities (Power, Information, BitRate) use The reason for Power was precision issues in earlier implementations, later fixed. Information/BitRate was chosen to use Some discussion here on Info/BitRate: So now what? A few ideas.Option 1) Change |
I knew there was a good reason for not supporting special cases. I just couldn't figure it all by myself. Thanks for the explanation. I would add another option to your two : go with generic maths and so give the possibility to use any value type as the underlying type holding the value. We've talked about it some months / years ago here. At the time generic math was experimental. Now it's there in the framework. Also there wasn't a clear use case to put the time and effort. This could be one. Moreso that having the possibility to go with float, for example, would support use cases where precision is secondary to storage space taken. Someone could even go wild and use Half for scenarios that make sense, all with having the huge benefits of using real units. For sure this would be a longer term option. For the short term I would go with Option 1. |
Generics may be a way forward, but we have tried it out a little bit and I find it a bit complicated to work with. I think it's an interesting path, but someone needs to put in time and effort to experiment and figure out how it will all fit together. I don't have the time myself. A few observations so far:
|
Updated the wiki page on this topic, a place to describe the state of this experiment and known challenges. https://github.com/angularsen/UnitsNet/wiki/Experimental:-Generic-Math-and-INumber |
If you want to help pursue option 1, you can help move #1195 forward. Then create a separate PR for supporting NaN/InF for quantities with |
supporting NaN, Inf+ or Inf-? would simplify things for us considerably (see Infinity error - Is it really that bad? · Issue #586 · angularsen/UnitsNet for earlier comments on this topic) Additionally, the recommended use of a Nullable<> has run into further issues with regard to the use of IQuantity as a generic and it being nullable while the subclasses like Pressure are not so we have an issue generalizing some of our classes. For instance
since IQuantity is nullable, the Nullable<> notation is considered redundant and the implementation of Pressure curve returns a Pressure[], not a Pressure?[] and so the previous suggestion of using a nullable to represent a NaN fails. |
Related work in progress: |
What is the rational behind throwing AwgumentException when the underlying double value for a unit is NaN, Inf+ or Inf-? With double we can sometimes use these special values to mean something. Inf+ or Inf- for example are "valid" in certain context. Shouldn't we just pass them along?
The text was updated successfully, but these errors were encountered: