TO SUPPORT MY WORK, ORDER A COMMERCIAL LICENSE
THANK YOU!
The tutorial consists of more than 200 live examples from 50 sections given separately for JAVA, C# and C++. 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, C# (the code for C# is almost identical) and C++. To copy the code, double-click inside the frame.
Case 1: Units of length / distance
Java/C# code
// JAVA: import org.mariuszgromada.math.mxparser.*;
// C#: using org.mariuszgromada.math.mxparser;
// ...
Expression e = new Expression("( 95*[cm] + 200*[m] + 1*[km] ) / [km]");
mXparser.consolePrintln("Res: " + e.getExpressionString() + " = " + e.calculate() );
C++ code
#include "org/mariuszgromada/math/mxparser.hpp"
// ...
ExpressionPtr e = new_Expression("( 95*[cm] + 200*[m] + 1*[km] ) / [km]");
mXparser::consolePrintln("Res: " + e->getExpressionString() + " = " + e->calculate() );
Code result
[mXparser-v.5.2.1] Res: ( 95*[cm] + 200*[m] + 1*[km] ) / [km] = 1.20095
Case 2: Units of time
Java/C# code
// JAVA: import org.mariuszgromada.math.mxparser.*;
// C#: using org.mariuszgromada.math.mxparser;
// ...
Expression e = new Expression("( 60*[min] + 2*[h] ) / [h]");
mXparser.consolePrintln("Res: " + e.getExpressionString() + " = " + e.calculate() );
C++ code
#include "org/mariuszgromada/math/mxparser.hpp"
// ...
ExpressionPtr e = new_Expression("( 60*[min] + 2*[h] ) / [h]");
mXparser::consolePrintln("Res: " + e->getExpressionString() + " = " + e->calculate() );
Code result
[mXparser-v.5.2.1] Res: ( 60*[min] + 2*[h] ) / [h] = 3.0
Case 3: Units of information
Java/C# code
// JAVA: import org.mariuszgromada.math.mxparser.*;
// C#: using org.mariuszgromada.math.mxparser;
// ...
Expression e = new Expression("8*[Mb] / [MB]");
mXparser.consolePrintln("Res: " + e.getExpressionString() + " = " + e.calculate() );
C++ code
#include "org/mariuszgromada/math/mxparser.hpp"
// ...
ExpressionPtr e = new_Expression("8*[Mb] / [MB]");
mXparser::consolePrintln("Res: " + e->getExpressionString() + " = " + e->calculate() );
Code result
[mXparser-v.5.2.1] Res: 8*[Mb] / [MB] = 1.0
Case 4: Units of volume
Java/C# code
// JAVA: import org.mariuszgromada.math.mxparser.*;
// C#: using org.mariuszgromada.math.mxparser;
// ...
Expression e = new Expression("2000*[l] / [m3]");
mXparser.consolePrintln("Res: " + e.getExpressionString() + " = " + e.calculate() );
C++ code
#include "org/mariuszgromada/math/mxparser.hpp"
// ...
ExpressionPtr e = new_Expression("2000*[l] / [m3]");
mXparser::consolePrintln("Res: " + e->getExpressionString() + " = " + e->calculate() );
Code result
[mXparser-v.5.2.1] Res: 2000*[l] / [m3] = 2.0
Case 5: Express 4 feet in inches
Java/C# code
// JAVA: import org.mariuszgromada.math.mxparser.*;
// C#: using org.mariuszgromada.math.mxparser;
// ...
Expression e = new Expression("4[ft]/[inch]");
mXparser.consolePrintln(e.getExpressionString() + " = " + e.calculate());
C++ code
#include "org/mariuszgromada/math/mxparser.hpp"
// ...
ExpressionPtr e = new_Expression("4[ft]/[inch]");
mXparser::consolePrintln(e->getExpressionString() + " = " + e->calculate());
Code result
[mXparser-v.5.2.1] 4[ft]/[inch] = 48.0
Case 6: Express in square kilometers the area of a rectangle measuring 100 meters by 2 kilometers
Java/C# code
// JAVA: import org.mariuszgromada.math.mxparser.*;
// C#: using org.mariuszgromada.math.mxparser;
// ...
Expression e = new Expression("100[m] * 2[km] / [km2]");
mXparser.consolePrintln(e.getExpressionString() + " = " + e.calculate());
C++ code
#include "org/mariuszgromada/math/mxparser.hpp"
// ...
ExpressionPtr e = new_Expression("100[m] * 2[km] / [km2]");
mXparser::consolePrintln(e->getExpressionString() + " = " + e->calculate());
Code result
[mXparser-v.5.2.1] 100[m] * 2[km] / [km2] = 0.2
Case 7: List of supported units
Java/C# code
// JAVA: import org.mariuszgromada.math.mxparser.*;
// C#: using org.mariuszgromada.math.mxparser;
// ...
mXparser.consolePrintHelp("type=unit");
C++ code
#include "org/mariuszgromada/math/mxparser.hpp"
// ...
mXparser::consolePrintHelp("type=unit");
Code result
[mXparser-v.5.2.1] Help content limited to query: 'type=unit'
# Keyword Type Syntax Since Description
- -------- ---- ------ ----- -----------
1. [%] <Unit> [%] 4.0 Percentage - Ratio / Fraction = 0.01 - Dimensionless unit
2. [%%] <Unit> [%%] 4.0 Promil, Per mille - Ratio / Fraction = 0.001 - Dimensionless unit
3. [Y] <Unit> [Y] 4.0 Septillion / Yotta - Metric prefix = 10²⁴ - Dimensionless unit
4. [sept] <Unit> [sept] 4.0 Septillion / Yotta - Metric prefix = 10²⁴ - Dimensionless unit
5. [Z] <Unit> [Z] 4.0 Sextillion / Zetta - Metric prefix = 10²¹ - Dimensionless unit
6. [sext] <Unit> [sext] 4.0 Sextillion / Zetta - Metric prefix = 10²¹ - Dimensionless unit
7. [E] <Unit> [E] 4.0 Quintillion / Exa - Metric prefix = 10¹⁸ - Dimensionless unit
8. [quint] <Unit> [quint] 4.0 Quintillion / Exa - Metric prefix = 10¹⁸ - Dimensionless unit
9. [P] <Unit> [P] 4.0 Quadrillion / Peta - Metric prefix = 10¹⁵ - Dimensionless unit
10. [quad] <Unit> [quad] 4.0 Quadrillion / Peta - Metric prefix = 10¹⁵ - Dimensionless unit
11. [T] <Unit> [T] 4.0 Trillion / Tera - Metric prefix = 10¹² - Dimensionless unit
12. [tril] <Unit> [tril] 4.0 Trillion / Tera - Metric prefix = 10¹² - Dimensionless unit
13. [G] <Unit> [G] 4.0 Billion / Giga - Metric prefix = 10⁹ - Dimensionless unit
14. [bil] <Unit> [bil] 4.0 Billion / Giga - Metric prefix = 10⁹ - Dimensionless unit
15. [M] <Unit> [M] 4.0 Million / Mega - Metric prefix = 10⁶ - Dimensionless unit
16. [mil] <Unit> [mil] 4.0 Million / Mega - Metric prefix = 10⁶ - Dimensionless unit
17. [k] <Unit> [k] 4.0 Thousand / Kilo - Metric prefix = 10³ - Dimensionless unit
18. [th] <Unit> [th] 4.0 Thousand / Kilo - Metric prefix = 10³ - Dimensionless unit
19. [hund] <Unit> [hund] 4.0 Hundred / Hecto - Metric prefix = 10² - Dimensionless unit
20. [hecto] <Unit> [hecto] 4.0 Hundred / Hecto - Metric prefix = 10² - Dimensionless unit
21. [ten] <Unit> [ten] 4.0 Ten / Deca - Metric prefix = 10 - Dimensionless unit
22. [deca] <Unit> [deca] 4.0 Ten / Deca - Metric prefix = 10 - Dimensionless unit
23. [deci] <Unit> [deci] 4.0 Tenth / Deci - Metric prefix = 10⁻¹ - Dimensionless unit
24. [centi] <Unit> [centi] 4.0 Hundredth / Centi - Metric prefix = 10⁻² - Dimensionless unit
25. [milli] <Unit> [milli] 4.0 Thousandth / Milli - Metric prefix = 10⁻³ - Dimensionless unit
26. [mic] <Unit> [mic] 4.0 Millionth / Micro - Metric prefix = 10⁻⁶ - Dimensionless unit
27. [n] <Unit> [n] 4.0 Billionth / Nano - Metric prefix = 10⁻⁹ - Dimensionless unit
28. [p] <Unit> [p] 4.0 Trillionth / Pico - Metric prefix = 10⁻¹² - Dimensionless unit
29. [f] <Unit> [f] 4.0 Quadrillionth / Femto - Metric prefix = 10⁻¹⁵ - Dimensionless unit
30. [a] <Unit> [a] 4.0 Quintillionth / Atoo - Metric prefix = 10⁻¹⁸ - Dimensionless unit
31. [z] <Unit> [z] 4.0 Sextillionth / Zepto - Metric prefix = 10⁻²¹ - Dimensionless unit
32. [y] <Unit> [y] 4.0 Septillionth / Yocto - Metric prefix = 10⁻²⁴ - Dimensionless unit
33. [m] <Unit> [m] 4.0 Meter - Unit of length [m] (m=1) - Unit
34. [km] <Unit> [km] 4.0 Kilometer - Unit of length [m] (m=1) - Unit
35. [cm] <Unit> [cm] 4.0 Centimeter - Unit of length [m] (m=1) - Unit
36. [mm] <Unit> [mm] 4.0 Millimeter - Unit of length [m] (m=1) - Unit
37. [inch] <Unit> [inch] 4.0 Inch - Unit of length [m] (m=1) - Unit
38. [yd] <Unit> [yd] 4.0 Yard - Unit of length [m] (m=1) - Unit
39. [ft] <Unit> [ft] 4.0 Feet - Unit of length [m] (m=1) - Unit
40. [mile] <Unit> [mile] 4.0 Mile - Unit of length [m] (m=1) - Unit
41. [nmi] <Unit> [nmi] 4.0 Nautical mile - Unit of length [m] (m=1) - Unit
42. [m2] <Unit> [m2] 4.0 Square meter - Unit of area [m²] (m=1) - Unit
43. [cm2] <Unit> [cm2] 4.0 Square centimeter - Unit of area [m²] (m=1) - Unit
44. [mm2] <Unit> [mm2] 4.0 Square millimeter - Unit of area [m²] (m=1) - Unit
45. [are] <Unit> [are] 4.0 Are - Unit of area [m²] (m=1) - Unit
46. [ha] <Unit> [ha] 4.0 Hectare - Unit of area [m²] (m=1) - Unit
47. [acre] <Unit> [acre] 4.0 Acre - Unit of area [m²] (m=1) - Unit
48. [km2] <Unit> [km2] 4.0 Square kilometer - Unit of area [m²] (m=1) - Unit
49. [mm3] <Unit> [mm3] 4.0 Cubic millimeter - Unit of volume [m³] (m=1) - Unit
50. [cm3] <Unit> [cm3] 4.0 Cubic centimeter - Unit of volume [m³] (m=1) - Unit
51. [m3] <Unit> [m3] 4.0 Cubic meter - Unit of volume [m³] (m=1) - Unit
52. [km3] <Unit> [km3] 4.0 Cubic kilometer - Unit of volume [m³] (m=1) - Unit
53. [ml] <Unit> [ml] 4.0 Milliliter - Unit of volume [m³] (m=1) - Unit
54. [l] <Unit> [l] 4.0 Liter - Unit of volume [m³] (m=1) - Unit
55. [gall] <Unit> [gall] 4.0 Gallon - Unit of volume [m³] (m=1) - Unit
56. [pint] <Unit> [pint] 4.0 Pint - Unit of volume [m³] (m=1) - Unit
57. [s] <Unit> [s] 4.0 Second - Unit of time [s] (s=1) - Unit
58. [ms] <Unit> [ms] 4.0 Millisecond - Unit of time [s] (s=1) - Unit
59. [min] <Unit> [min] 4.0 Minute - Unit of time [s] (s=1) - Unit
60. [h] <Unit> [h] 4.0 Hour - Unit of time [s] (s=1) - Unit
61. [day] <Unit> [day] 4.0 Day - Unit of time [s] (s=1) - Unit
62. [week] <Unit> [week] 4.0 Week - Unit of time [s] (s=1) - Unit
63. [yearj] <Unit> [yearj] 4.0 Julian year = 365.25 days - Unit of time [s] (s=1) - Unit
64. [kg] <Unit> [kg] 4.0 Kilogram - Unit of mass [kg] (kg=1) - Unit
65. [gr] <Unit> [gr] 4.0 Gram - Unit of mass [kg] (kg=1) - Unit
66. [mg] <Unit> [mg] 4.0 Milligram - Unit of mass [kg] (kg=1) - Unit
67. [dag] <Unit> [dag] 4.0 Decagram - Unit of mass [kg] (kg=1) - Unit
68. [t] <Unit> [t] 4.0 Tonne - Unit of mass [kg] (kg=1) - Unit
69. [oz] <Unit> [oz] 4.0 Ounce - Unit of mass [kg] (kg=1) - Unit
70. [lb] <Unit> [lb] 4.0 Pound - Unit of mass [kg] (kg=1) - Unit
71. [b] <Unit> [b] 4.0 Bit - Unit of information [bit] (bit=1) - Unit
72. [kb] <Unit> [kb] 4.0 Kilobit - Unit of information [bit] (bit=1) - Unit
73. [Mb] <Unit> [Mb] 4.0 Megabit - Unit of information [bit] (bit=1) - Unit
74. [Gb] <Unit> [Gb] 4.0 Gigabit - Unit of information [bit] (bit=1) - Unit
75. [Tb] <Unit> [Tb] 4.0 Terabit - Unit of information [bit] (bit=1) - Unit
76. [Pb] <Unit> [Pb] 4.0 Petabit - Unit of information [bit] (bit=1) - Unit
77. [Eb] <Unit> [Eb] 4.0 Exabit - Unit of information [bit] (bit=1) - Unit
78. [Zb] <Unit> [Zb] 4.0 Zettabit - Unit of information [bit] (bit=1) - Unit
79. [Yb] <Unit> [Yb] 4.0 Yottabit - Unit of information [bit] (bit=1) - Unit
80. [B] <Unit> [B] 4.0 Byte - Unit of information [bit] (bit=1) - Unit
81. [kB] <Unit> [kB] 4.0 Kilobyte - Unit of information [bit] (bit=1) - Unit
82. [MB] <Unit> [MB] 4.0 Megabyte - Unit of information [bit] (bit=1) - Unit
83. [GB] <Unit> [GB] 4.0 Gigabyte - Unit of information [bit] (bit=1) - Unit
84. [TB] <Unit> [TB] 4.0 Terabyte - Unit of information [bit] (bit=1) - Unit
85. [PB] <Unit> [PB] 4.0 Petabyte - Unit of information [bit] (bit=1) - Unit
86. [EB] <Unit> [EB] 4.0 Exabyte - Unit of information [bit] (bit=1) - Unit
87. [ZB] <Unit> [ZB] 4.0 Zettabyte - Unit of information [bit] (bit=1) - Unit
88. [YB] <Unit> [YB] 4.0 Yottabyte - Unit of information [bit] (bit=1) - Unit
89. [J] <Unit> [J] 4.0 Joule - Unit of energy [J] (m=1, kg=1, s=1) - Unit
90. [eV] <Unit> [eV] 4.0 Electronovolt - Unit of energy [J] (m=1, kg=1, s=1) - Unit
91. [keV] <Unit> [keV] 4.0 Kiloelectronovolt - Unit of energy [J] (m=1, kg=1, s=1) - Unit
92. [MeV] <Unit> [MeV] 4.0 Megaelectronovolt - Unit of energy [J] (m=1, kg=1, s=1) - Unit
93. [GeV] <Unit> [GeV] 4.0 Gigaelectronovolt - Unit of energy [J] (m=1, kg=1, s=1) - Unit
94. [TeV] <Unit> [TeV] 4.0 Teraelectronovolt - Unit of energy [J] (m=1, kg=1, s=1) - Unit
95. [m/s] <Unit> [m/s] 4.0 Meter per second - Unit of speed [m/s] (m=1, s=1) - Unit
96. [km/h] <Unit> [km/h] 4.0 Kilometer per hour - Unit of speed [m/s] (m=1, s=1) - Unit
97. [mi/h] <Unit> [mi/h] 4.0 Mile per hour - Unit of speed [m/s] (m=1, s=1) - Unit
98. [knot] <Unit> [knot] 4.0 Knot - Unit of speed [m/s] (m=1, s=1) - Unit
99. [m/s2] <Unit> [m/s2] 4.0 Meter per square second - Unit of acceleration [m/s²] (m=1, s=1) - Unit
100. [km/h2] <Unit> [km/h2] 4.0 Kilometer per square hour - Unit of acceleration [m/s²] (m=1, s=1) - Unit
101. [mi/h2] <Unit> [mi/h2] 4.0 Mile per square hour - Unit of acceleration [m/s²] (m=1, s=1) - Unit
102. [rad] <Unit> [rad] 4.0 Radian - Unit of angle [rad] (rad=1) - Unit
103. [deg] <Unit> [deg] 4.0 Degree of arc - Unit of angle [rad] (rad=1) - Unit
104. ['] <Unit> ['] 4.0 Minute of arc - Unit of angle [rad] (rad=1) - Unit
105. [''] <Unit> [''] 4.0 Second of arc - Unit of angle [rad] (rad=1) - Unit
[mXparser-v.5.2.1]
Nuget – Package Manager (C#, F#, Visual Basic, …)
Install-Package
MathParser.org-mXparser
-Version
6.1.0
dotnet add package
MathParser.org-mXparser
--version
6.1.0
<PackageReference Include=
"MathParser.org-mXparser"
Version=
"6.1.0"
/>
Maven – Dependency (Java, Kotlin, Scala, Groovy, …)
<dependency>
<groupid>org.mariuszgromada.math
</groupid>
<artifactid>MathParser.org-mXparser
</artifactid>
<version>6.1.0
</version>
</dependency>
Maven – Gradle
implementation
'org.mariuszgromada.math:MathParser.org-mXparser:6.1.0'
CMake – Dependency / FetchContent (C++, MSVC, LLVM/Clang, GNU/GCC, MinGW, MSYS2, WSL, Windows, Linux, Unix, MacOS)
include(FetchContent)
FetchContent_Declare(
MathParserOrgMxParser
GIT_REPOSITORY https://github.com/mariuszgromada/MathParser.org-mXparser.git
GIT_TAG v.6.1.0
SOURCE_SUBDIR CURRENT/cpp/lib
)
FetchContent_MakeAvailable(MathParserOrgMxParser
)
target_link_libraries(YourExecutable MathParserOrgMxParser
)
GitHub
git clone
https://github.com/mariuszgromada/MathParser.org-mXparser
OTHER DOWNLOAD OPTIONS
Download latest release – v.6.1.0 Sagitara: .NET bin onlyDownload latest release – v.6.1.0 Sagitara: JAVA bin onlyDownload latest release – v.6.1.0 Sagitara: bin + doc
NEWS FROM MATHPARSER.ORG
SOURCE CODE
Source code .zipSource code .tar.gz
View on GitHubMathSpace.pl