Working with NaN – Not-a-Number

TO SUPPORT MY WORK, ORDER A COMMERCIAL LICENSE
THANK YOU!

Tutorial Math Collection API spec Download

Below is the code for JAVA, the code for C# is almost identical.

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.5.0.0] Res 1: x = 1.0, if( isNaN( 2 / x ), 1, -1 ) = -1.0
[mXparser-v.5.0.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.5.0.0] Res 1: x = 1.0, if( x >= 1, 1, [NaN] ) = 1.0
[mXparser-v.5.0.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.5.0.0] Res 1: x = 1.0, coalesce( 2/0 , x , 3) = 1.0
[mXparser-v.5.0.0] Res 2: x = NaN, coalesce( 2/0 , x , 3) = 3.0
Nuget – Package Manager

Install-Package MathParser.org-mXparser -Version 5.0.7

Nuget – .NET CLI

dotnet add package MathParser.org-mXparser --version 5.0.7

Nuget – Package Reference

<PackageReference Include="MathParser.org-mXparser" Version="5.0.7"/>

Maven – Dependency

<dependency>
<groupid>
org.mariuszgromada.math</groupid>
<artifactid>
MathParser.org-mXparser</artifactid>
<version>
5.0.7</version>
</dependency>

Maven – Gradle

implementation 'org.mariuszgromada.math:MathParser.org-mXparser:5.0.7'

Maven – Gradle (Kotlin)

implementation("org.mariuszgromada.math:MathParser.org-mXparser:5.0.7")

GitHub

git clone https://github.com/mariuszgromada/MathParser.org-mXparser

OTHER DOWNLOAD OPTIONS

Download latest release – v.5.0.7 Leonis: .NET bin onlyDownload latest release – v.5.0.7 Leonis: JAVA bin onlyDownload latest release – v.5.0.7 Leonis: bin + doc

NEWS FROM MATHPARSER.ORG
SOURCE CODE

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

DONATION
Did you find the software useful?
Please consider donation 🙂
DONATE