Movement against float.init being nan
Bastiaan Veelo
Bastiaan at Veelo.net
Mon Aug 22 20:29:57 UTC 2022
On Saturday, 20 August 2022 at 03:12:43 UTC, Steven Schveighoffer
wrote:
> In other words, NaN is silent. You can't even `assert(x !=
> double.init)`. You have to use an esoteric function `isNaN` for
> that.
I had some fun with `isNaN` the other day. We used it to check
for initialisation in an access function to cache an expensive
computation. This worked brilliantly until we noticed a
malfunction in the release version. It took a while until I
realised that I had given the LDC `fastmath` option to the
release build, which assumes NaN does not occur, which makes
`isNaN` misbehave.
What I learned from this is to not use this flag globally, and
add select attributes to select functions instead. And instead
of using NaN I now use `std.typecons.Nullable` to signal a dirty
cache.
— Bastiaan.
More information about the Digitalmars-d
mailing list