float price; if (price == float.nan) { // initialized } else { // uninitialized } ... valid ?
Andre Pany
andre at s-e-a-p.de
Wed Jun 30 16:24:38 UTC 2021
On Wednesday, 30 June 2021 at 03:15:46 UTC, someone wrote:
> Is the following code block valid ?
>
> ```d
> float price; /// initialized as float.nan by default ... right ?
>
> if (price == float.nan) {
>
> /// writeln("initialized");
>
> } else {
>
> /// writeln("uninitialized");
>
> }
> ```
>
> if so, the following one should be valid too ... right ?
>
> ```d
> float price;
>
> if (price != float.nan) {
>
> /// writeln("initialized");
>
> }
> ```
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.
Kind regards
Andre
More information about the Digitalmars-d-learn
mailing list