Radians Mode / Degrees Mode

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

The tutorial consists of more than 200 live examples from 50 sections. Each of the examples can be copied and run on your own environment. In addition, mXparser provides an extensive collection of over 500 built-in math functions, expressions and symbols. Familiarize yourself with the scope and the syntax. Live testing is the best way to learn. Good luck! 🙂

Tutorial Math Collection API spec Download

Below is the code for JAVA, the code for C# is almost identical. To copy the code, double-click inside the frame.

Case 1: Basic trigonometric function

// JAVA: import org.mariuszgromada.math.mxparser.*;
// C#: using 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.2.1] ----- Default behaviour ----- 
[mXparser-v.5.2.1] Radians Mode = true, Degrees Mode = false
[mXparser-v.5.2.1] sin(π) = 0.0
[mXparser-v.5.2.1] sin(180) = -0.8011526357338304
[mXparser-v.5.2.1] ----- Degrees Mode ----- 
[mXparser-v.5.2.1] Radians Mode = false, Degrees Mode = true
[mXparser-v.5.2.1] sin(π) = 0.05480366514878953
[mXparser-v.5.2.1] sin(180) = 0.0
[mXparser-v.5.2.1] ----- Returning to Radians Mode ----- 
[mXparser-v.5.2.1] Radians Mode = true, Degrees Mode = false
[mXparser-v.5.2.1] sin(π) = 0.0
[mXparser-v.5.2.1] sin(180) = -0.8011526357338304

Case 2: Inverse trigonometric function

// JAVA: import org.mariuszgromada.math.mxparser.*;
// C#: using org.mariuszgromada.math.mxparser;
// ...
Expression e = new Expression("acos(-1)");

/* Default behaviour */
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.2.1] ----- Default behaviour ----- 
[mXparser-v.5.2.1] Radians Mode = true, Degrees Mode = false
[mXparser-v.5.2.1] acos(-1) = 3.141592653589793
[mXparser-v.5.2.1] ----- Degrees Mode ----- 
[mXparser-v.5.2.1] Radians Mode = false, Degrees Mode = true
[mXparser-v.5.2.1] acos(-1) = 180.0
[mXparser-v.5.2.1] ----- Returning to Radians Mode ----- 
[mXparser-v.5.2.1] Radians Mode = true, Degrees Mode = false
[mXparser-v.5.2.1] acos(-1) = 3.141592653589793

Case 3: Using units of angle being in radians mode

// JAVA: import org.mariuszgromada.math.mxparser.*;
// C#: using 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.2.1] Radians Mode = true, Degrees Mode = false
[mXparser-v.5.2.1] sin(π) = 0.0
[mXparser-v.5.2.1] sin(π[rad]) = 0.0
[mXparser-v.5.2.1] sin(180) = -0.8011526357338304
[mXparser-v.5.2.1] sin(180[deg]) = 0.0
Nuget – Package Manager

Install-Package MathParser.org-mXparser -Version 5.2.1

Nuget – .NET CLI

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

Nuget – Package Reference

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

Maven – Dependency

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

Maven – Gradle

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

Maven – Gradle (Kotlin)

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

GitHub

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

OTHER DOWNLOAD OPTIONS

Download latest release – v.5.2.1 Orion: .NET bin onlyDownload latest release – v.5.2.1 Orion: JAVA bin onlyDownload latest release – v.5.2.1 Orion: bin + doc

NEWS FROM MATHPARSER.ORG
SOURCE CODE

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

My other creative spaces

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