danielwertheim / Ensure.That

Guard clause project for .NET
MIT License
438 stars 49 forks source link

Missing validation for double and float against NaN #182

Open DanAvni opened 6 months ago

DanAvni commented 6 months ago

Please add support for checking if a double or float has or does not have a value of NaN. checking that a double or float has a value like this Ensure.That(x).IsNot(double.NaN) does not work. see https://learn.microsoft.com/en-us/dotnet/api/system.double.nan?view=net-8.0

ndrwrbgs commented 6 months ago

Hey @DanAvni 👋

Thanks for the bug report, that does seem against expectations (see below).

It’s been a while since the last activity on this library - myself, I’ve been over in Go- and Python-land. If you have the bandwidth to prepare a PR, that’d go a long way towards getting the change in. ComparableArg.double.cs is a starting place.

Performance checklist

I don’t have concerns over using a method call here instead of ==, since the result is incorrect today. We do want to avoid boxing/allocations on the happy path to decrease upgrade-cost to consumers (double.Equals instead of casting to an IComparable as mentioned below should do the job efficiently).

Work around

If that’s not possible at this time, you could use the Extension Method support to locally add…

static double IsNotNaN(this Param<double> src)

Confirmation