float price; if (price == float.nan) { // initialized } else { // uninitialized } ... valid ?

someone someone at somewhere.com
Wed Jun 30 16:41:40 UTC 2021


On Wednesday, 30 June 2021 at 16:24:38 UTC, Andre Pany wrote:

> Side note: in case you want to work with money, you may 
> consider using a specific data type like 
> https://code.dlang.org/packages/money instead of float/double.

Yes, I've seen it, and in a previous-unrelated post I commented I 
am planning to use it (or something similar) because floats and 
currency are a horrible combo. I am not using it right now 
because I want to learn the language and encountering situations 
like this one helps me a lot, otherwise, I would have never noted 
such NaN behavior -to me, there are a lots of things that could 
fly under the radar at this moment. And by the way, looking at 
the code, money seems a quite simple non-nonsense implementation 
making it a solid candidate :)

Thanks for the tip Andre !




More information about the Digitalmars-d-learn mailing list