Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing validation for double and float against NaN #182

Open
DanAvni opened this issue Mar 7, 2024 · 1 comment
Open

Missing validation for double and float against NaN #182

DanAvni opened this issue Mar 7, 2024 · 1 comment

Comments

@DanAvni
Copy link

DanAvni commented Mar 7, 2024

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
Copy link
Contributor

ndrwrbgs commented Mar 7, 2024

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

  • In the BCL == is false but any method-based equality or comparison is True
  • If the double typehint is lost in EnsureThat, and IComparable<double> is kept instead, the result is true (The IComparable method uses CompareTo, the double override-method uses ==)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants