Radians Mode / Degrees Mode

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: Basic trigonometric function

import org.mariuszgromada.math.mxparser.*;
...
Expression eRad = new Expression("sin(π)");
Expression eDeg = new Expression("sin(180)");
/* Default behaviour */
mXparser.consolePrintln("----- Default behaviour ----- ");
mXparser.consolePrintln("Radians Mode = " + mXparser.checkIfRadiansMode() + ", Degrees Mode = " + mXparser.checkIfDegreesMode());
mXparser.consolePrintln(eRad.getExpressionString() + " = " + eRad.calculate());
mXparser.consolePrintln(eDeg.getExpressionString() + " = " + eDeg.calculate());
/* Set Degrees Mode */
mXparser.consolePrintln("----- Degrees Mode ----- ");
mXparser.setDegreesMode();
mXparser.consolePrintln("Radians Mode = " + mXparser.checkIfRadiansMode() + ", Degrees Mode = " + mXparser.checkIfDegreesMode());
mXparser.consolePrintln(eRad.getExpressionString() + " = " + eRad.calculate());
mXparser.consolePrintln(eDeg.getExpressionString() + " = " + eDeg.calculate());
/* Returning to Radians Mode */
mXparser.consolePrintln("----- Returning to Radians Mode ----- ");
mXparser.setRadiansMode();
mXparser.consolePrintln("Radians Mode = " + mXparser.checkIfRadiansMode() + ", Degrees Mode = " + mXparser.checkIfDegreesMode());
mXparser.consolePrintln(eRad.getExpressionString() + " = " + eRad.calculate());
mXparser.consolePrintln(eDeg.getExpressionString() + " = " + eDeg.calculate());
[mXparser-v.5.0.4] ----- Default behaviour ----- 
[mXparser-v.5.0.4] Radians Mode = true, Degrees Mode = false
[mXparser-v.5.0.4] sin(π) = 0.0
[mXparser-v.5.0.4] sin(180) = -0.8011526357338304
[mXparser-v.5.0.4] ----- Degrees Mode ----- 
[mXparser-v.5.0.4] Radians Mode = false, Degrees Mode = true
[mXparser-v.5.0.4] sin(π) = 0.05480366514878953
[mXparser-v.5.0.4] sin(180) = 0.0
[mXparser-v.5.0.4] ----- Returning to Radians Mode ----- 
[mXparser-v.5.0.4] Radians Mode = true, Degrees Mode = false
[mXparser-v.5.0.4] sin(π) = 0.0
[mXparser-v.5.0.4] sin(180) = -0.8011526357338304

Case 2: Inverse trigonometric function

import org.mariuszgromada.math.mxparser.*;
...
mXparser.consolePrintln("----- Default behaviour ----- ");
mXparser.consolePrintln("Radians Mode = " + mXparser.checkIfRadiansMode() + ", Degrees Mode = " + mXparser.checkIfDegreesMode());
mXparser.consolePrintln(e.getExpressionString() + " = " + e.calculate());
/* Set Degrees Mode */
mXparser.consolePrintln("----- Degrees Mode ----- ");
mXparser.setDegreesMode();
mXparser.consolePrintln("Radians Mode = " + mXparser.checkIfRadiansMode() + ", Degrees Mode = " + mXparser.checkIfDegreesMode());
mXparser.consolePrintln(e.getExpressionString() + " = " + e.calculate());
/* Returning to Radians Mode */
mXparser.consolePrintln("----- Returning to Radians Mode ----- ");
mXparser.setRadiansMode();
mXparser.consolePrintln("Radians Mode = " + mXparser.checkIfRadiansMode() + ", Degrees Mode = " + mXparser.checkIfDegreesMode());
mXparser.consolePrintln(e.getExpressionString() + " = " + e.calculate());
[mXparser-v.5.0.4] ----- Default behaviour ----- 
[mXparser-v.5.0.4] Radians Mode = true, Degrees Mode = false
[mXparser-v.5.0.4] acos(-1) = 3.141592653589793
[mXparser-v.5.0.4] ----- Degrees Mode ----- 
[mXparser-v.5.0.4] Radians Mode = false, Degrees Mode = true
[mXparser-v.5.0.4] acos(-1) = 180.0
[mXparser-v.5.0.4] ----- Returning to Radians Mode ----- 
[mXparser-v.5.0.4] Radians Mode = true, Degrees Mode = false
[mXparser-v.5.0.4] acos(-1) = 3.141592653589793

Case 3: Using units of angle being in radians mode

import org.mariuszgromada.math.mxparser.*;
...
Expression e1 = new Expression("sin(π)");
Expression e2 = new Expression("sin(π[rad])");
Expression e3 = new Expression("sin(180)");
Expression e4 = new Expression("sin(180[deg])");
mXparser.consolePrintln("Radians Mode = " + mXparser.checkIfRadiansMode() + ", Degrees Mode = " + mXparser.checkIfDegreesMode());
mXparser.consolePrintln(e1.getExpressionString() + " = " + e1.calculate());
mXparser.consolePrintln(e2.getExpressionString() + " = " + e2.calculate());
mXparser.consolePrintln(e3.getExpressionString() + " = " + e3.calculate());
mXparser.consolePrintln(e4.getExpressionString() + " = " + e4.calculate());
[mXparser-v.5.0.4] Radians Mode = true, Degrees Mode = false
[mXparser-v.5.0.4] sin(π) = 0.0
[mXparser-v.5.0.4] sin(π[rad]) = 0.0
[mXparser-v.5.0.4] sin(180) = -0.8011526357338304
[mXparser-v.5.0.4] sin(180[deg]) = 0.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