float price; if (price == float.nan) { // initialized } else { // uninitialized } ... valid ?
Mathias LANG
geod24 at gmail.com
Wed Jun 30 04:15:55 UTC 2021
On Wednesday, 30 June 2021 at 04:03:24 UTC, someone wrote:
> On Wednesday, 30 June 2021 at 03:51:47 UTC, Mathias LANG wrote:
>
> ... is far from pretty but it works as expected, thanks for
> your tip !
Can be made a bit prettier with UFCS:
> ```d
> import std.math : isNaN;
>
> float lnumStockPricePreceding;
>
> foreach (float lnumStockPrice; ludtStockPriceEvolution.range)
>
> if (!lnumStockPricePreceding.isNan) {
>
> /// do something
>
> }
>
> lnumStockPricePreceding = lnumStockPrice;
>
> }
> ```
Or even better, with ranges:
> ```d
> import std.math : isNaN;
>
> float lnumStockPricePreceding;
>
> foreach (float lnumStockPrice;
> ludtStockPriceEvolution.range.filter!(f => !f.isNan))
> /// do something
>
> lnumStockPricePreceding = lnumStockPrice;
>
> }
> ```
More information about the Digitalmars-d-learn
mailing list