C#, VS 2010
I need to determine if a float value is NaN.
Testing a float for NaN using
float.IsNaN(aFloatNumber)
crashes with a stack overflow.
So does
aFloatNumber.CompareTo(float.NaN).
The following does not crash, but it's not useful as it returns NaN regardless:
aFloatNumber - float.NaN
A search for "stack overflow" returns results about this website instead of results about an actual stack overflow, so I can't find relevant answers.
Why is my application going into a stack overflow when testing for NaN?
Edit: the call stack:
Edit: it's clearly something in my code: this statement:
bool aaa = float.IsNaN(float.NaN);
- works OK in the constructor of the application, right after InitializeComponent();
- works OK in the constructor of theclass for a custom control, right after InitializeComponent();
- but crashes in an event handler inside the class for a custom control.
So, this is what I am doing:
- Abstract Custom control: public abstract partial class ConfigNumberBaseBox : TextBox
- has a Validating event handler ValidateTextBoxEntry
- ValidateTextBoxEntry is defined inside the ConfigNumberBaseBox class
- Custom control that inherits from ConfigNumberBaseBox : public partial class ConfigTemperBox : ConfigNumberBaseBox
- Run the app
- When I finish editing a ConfigTemperBox control, ValidateTextBoxEntry is called
- ValidateTextBoxEntry runs fine until it encounters float.IsNaN
- stack overflow
Edit:
Debug.WriteLine() shows that the code is executed only once: no recursion.
Edit:
This works:
float fff = 0F;
int iii = fff.CompareTo(float.PositiveInfinity);
This crashes:
float fff = 0F;
int iii = fff.CompareTo(float.NaN);