Working with NaN - Not-a-Number

mXparser - logo

Did you find the software useful? Please consider donation 🙂
Developing and maintaining MathParser.org-mXparser takes a lot of time, mainly my free time. I hope it saved some of your time. If yes, then buy me a coffee 🙂
DONATE

JAVA code

Case 1: NaN in condition

import org.mariuszgromada.math.mxparser.*;
...
Argument x = new Argument("x = 1");
Expression e = new Expression("if( isNaN( 2 / x ), 1, -1 )", x);
mXparser.consolePrintln("Res 1: x = " + x.getArgumentValue() + ", " + e.getExpressionString() + " = " + e.calculate());
x.setArgumentValue(0);
mXparser.consolePrintln("Res 2: x = " + x.getArgumentValue() + ", " + e.getExpressionString() + " = " + e.calculate());
[mXparser-v.4.1.0] Res 1: x = 1.0, if( isNaN( 2 / x ), 1, -1 ) = -1.0
[mXparser-v.4.1.0] Res 2: x = 0.0, if( isNaN( 2 / x ), 1, -1 ) = 1.0

Case 2: NaN symbol

import org.mariuszgromada.math.mxparser.*;
...
Argument x = new Argument("x = 1");
Expression e = new Expression("if( x >= 1, 1, [NaN] )", x);
mXparser.consolePrintln("Res 1: x = " + x.getArgumentValue() + ", " + e.getExpressionString() + " = " + e.calculate());
x.setArgumentValue(0);
mXparser.consolePrintln("Res 2: x = " + x.getArgumentValue() + ", " + e.getExpressionString() + " = " + e.calculate());
[mXparser-v.4.1.0] Res 1: x = 1.0, if( x >= 1, 1, [NaN] ) = 1.0
[mXparser-v.4.1.0] Res 2: x = 0.0, if( x >= 1, 1, [NaN] ) = NaN

Case 3: First non-NaN valueon the list

import org.mariuszgromada.math.mxparser.*;
...
Argument x = new Argument("x = 1");
Expression e = new Expression("coalesce( 2/0 , x , 3)", x);
mXparser.consolePrintln("Res 1: x = " + x.getArgumentValue() + ", " + e.getExpressionString() + " = " + e.calculate());
x.setArgumentValue(Double.NaN);
mXparser.consolePrintln("Res 2: x = " + x.getArgumentValue() + ", " + e.getExpressionString() + " = " + e.calculate());
[mXparser-v.4.1.0] Res 1: x = 1.0, coalesce( 2/0 , x , 3) = 1.0
[mXparser-v.4.1.0] Res 2: x = NaN, coalesce( 2/0 , x , 3) = 3.0

*** If you found the software useful donation is something you might consider 🙂 ***

If you found the software useful donation is something you might consider :-)

Enjoy! 🙂

 

Best regards,

Mariusz Gromada

Download latest release – v.4.1.1 Aeries: bin + doc + src (.zip 13.4 MB)

Download latest release – v.4.1.1 Aeries: bin only (.zip 4.35 MB) – separate binaries for java: 1.5, 1.6, 1.7, 1.8; .NET: 2.0, 3.0, 3.5, 4.0, 4.5, 4.6, 4.7, .NET Core, .NET Standard, .NET PCL, Xamarin.Android, Xamarin.iOS

Source code .zipSource code .tar.gz View on GitHubMathSpace.pl