Numerical conditions

Dec 16, 2009 at 10:10 PM
Edited Dec 16, 2009 at 10:19 PM

It would be nice if the conditions for double/single/decimal supported a way to check that a parameter is not NaN, Infiniti (or pos inf/neg inf).

Something like:

Condition.Requires(param, "param").IsNotNaN().IsNotInfiniti();

 

In the meantime, I'm just adding my own extensions for this, but it seems like a very common check you'd want to make, that should be in the library by default.

Coordinator
Dec 17, 2009 at 6:53 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Dec 17, 2009 at 3:59 PM

Here are some alternative namings:

  • IsANumber
  • IsNumber
  • IsNotANumber
  • IsNotNumber

I have some trouble putting a double negation and abbreviations in a method name. 'is not not a number' is not a great name for a method.

What do you think?

Dec 17, 2009 at 8:43 PM

I have some trouble putting a double negation and abbreviations in a method name. 'is not not a number' is not a great name for a method.

What do you think?

I understand, and normally agree, however, in this case, you're kind of working against the method being self-documenting.  In this case, IsNumber (or IsValidNumber?) is the most reasonable, but...

Since you're checking against double.NaN, it's hard for me to want to not have NaN in the name, since that makes it obvious.  Doing

double value = 3;
Condition.Requires(value, "value").IsNumber();

Seems "wrong" and counter-intuitive - how can a double not be a number? 

Granted, it's only via NaN, so I don't hate this, but it is odd... 

IsNaN() is nice, especially since it matches up nicely with Double.IsNaN(), but that ends up being the opposite of the check you'd typically want to make.  You're already using IsNotXXX in most places (IsNotInRange, IsNotNull, IsNotOfType, IsNotLonger..., IsNotShorter...), which was why I suggested IsNotNaN (even though "is not not a number" is odd).

 

Dec 17, 2009 at 8:50 PM

Even if there is a double negation in IsNotNaN, I think that method name really expresses what it does: a double value is not equal to double.NaN. I would go with that name even if it could seem "wrong" gramatically thinking about it in detail.

Just my 2 cents :) Regards,

Vicente