-
Notifications
You must be signed in to change notification settings - Fork 14
Feature request: isnan() function #22
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
Comments
Yeah, both of these scenarios should return NaN, unless you disagree. Thoughts? |
I initially expected Then I tried So I checked the IEEE standard and found this: Any comparison with NaN (except !=) will return false, including comparing NaN with itself.
So the current behavior perfectly conforms to the standard! But then, how do I compare a number to NaN in tinyexpr++? It seems the library lacks an equivalent to Oddly enough, there is a |
This will evaluate to NaN. It basically behaves like |
Yes, I need to add an |
Yeah, in C++ comparing NaN with NaN will produce the IEEE standard results...but I'm just not liking that at all. In Excel, |
I'm not opposed to it, but frankly both ways sound unnatural to me. |
For those landing here: Until ISNAN() is supported natively, it can be added manually using a custom function: #include "tinyexpr.h"
#include <iostream>
double isnan(double val) {
return std::isnan(val) ? 1.0 : 0.0;
}
int main() {
const double x = std::numeric_limits<float>::quiet_NaN();
te_parser tep;
tep.set_variables_and_functions({{"x", &x}, {"ISNAN", isnan}});
const double result = tep.evaluate("ISNAN(x)");
std::cout << "The expression " << tep.get_expression() << " evaluates to " << result << "\n";
} |
Although this is different from the C++ standard, this is how spreadsheet formulas work and is (IMO) more intuitive. #22
I'm witnessing the following behavior when evaluating an expression:
nan == nan
returns 0.0nan != nan
returns 1.0The text was updated successfully, but these errors were encountered: