Built-in constants

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: Using built-in constants

Java/C# code
// JAVA: import org.mariuszgromada.math.mxparser.*;
// C#: using org.mariuszgromada.math.mxparser;
// ...
Expression e = new Expression("pi+e");
mXparser.consolePrintln("Res: " + e.getExpressionString() + " = " + e.calculate());
C++ code
#include "org/mariuszgromada/math/mxparser.hpp"
// ...
ExpressionPtr e = new_Expression("pi+e");
mXparser::consolePrintln("Res: " + e->getExpressionString() + " = " + e->calculate());
Code result
[mXparser-v.5.2.1] Res: pi+e = 5.859874482048838

Case 2: Estimating Moon gravitational acceleration

Java/C# code
// JAVA: import org.mariuszgromada.math.mxparser.*;
// C#: using org.mariuszgromada.math.mxparser;
// ...
Expression e = new Expression("( [G.] * [Moon-M] / [Moon-R]^2 ) * ( [m] / [s]^2 )");
mXparser.consolePrintln("Res: " + e.getExpressionString() + " = " + e.calculate());
C++ code
#include "org/mariuszgromada/math/mxparser.hpp"
// ...
ExpressionPtr e = new_Expression("( [G.] * [Moon-M] / [Moon-R]^2 ) * ( [m] / [s]^2 )");
mXparser::consolePrintln("Res: " + e->getExpressionString() + " = " + e->calculate());
Code result
[mXparser-v.5.2.1] Res: ( [G.] * [Moon-M] / [Moon-R]^2 ) * ( [m] / [s]^2 ) = 1.6247349715841357

Case 3: Getting list of constants

Java/C# code
// JAVA: import org.mariuszgromada.math.mxparser.*;
// C#: using org.mariuszgromada.math.mxparser;
// ...
Expression e = new Expression();
mXparser.consolePrintln(e.getHelp("constant"));   
C++ code
#include "org/mariuszgromada/math/mxparser.hpp"
// ...
ExpressionPtr e = new_Expression();
mXparser::consolePrintln(e->getHelp("constant"));
Code result
[mXparser-v.5.2.1] Help content limited to query: 'constant'
  #  Keyword             Type                    Syntax                                        Since Description
  -  --------            ----                    ------                                        ----- -----------
  1. π                   <Constant value>        π                                             5.0   Pi, Archimedes' or Ludolph's number - Mathematical constant π - Constant value - Unicode math symbol
  2. ℼ                   <Constant value>        ℼ                                             5.0   Pi, Archimedes' or Ludolph's number - Mathematical constant π - Constant value - Unicode math symbol
  3. pi                  <Constant value>        pi                                            1.0   Pi, Archimedes' or Ludolph's number - Mathematical constant π - Constant value
  4. e                   <Constant value>        e                                             1.0   Napier's or Euler's number (base of Natural logarithm) - Mathematical constant e - Constant value
  5. ℯ                   <Constant value>        ℯ                                             5.0   Napier's or Euler's number (base of Natural logarithm) - Mathematical constant e - Constant value - Unicode math symbol
  6. ⅇ                   <Constant value>        ⅇ                                             5.0   Napier's or Euler's number (base of Natural logarithm) - Mathematical constant e - Constant value - Unicode math symbol
  7. [gam]               <Constant value>        [gam]                                         1.0   Euler-Mascheroni constant - Mathematical constant γ - Constant value
  8. [phi]               <Constant value>        [phi]                                         1.0   Golden ratio - Mathematical constant φ - Constant value
  9. [PN]                <Constant value>        [PN]                                          1.0   Plastic constant - Mathematical constant ρ - Constant value
 10. [B*]                <Constant value>        [B*]                                          1.0   Embree-Trefethen constant - Mathematical constant β* - Constant value
 11. [F'd]               <Constant value>        [F'd]                                         1.0   Feigenbaum delta constant - Mathematical constant δ - Constant value
 12. [F'a]               <Constant value>        [F'a]                                         1.0   Feigenbaum alpha constant - Mathematical constant α - Constant value
 13. [C2]                <Constant value>        [C2]                                          1.0   Twin prime constant - Mathematical constant ∏₂ - Constant value
 14. [M1]                <Constant value>        [M1]                                          1.0   Meissel-Mertens constant - Mathematical constant M₁, B₁ - Constant value
 15. [B2]                <Constant value>        [B2]                                          1.0   Brun's constant for twin primes - Mathematical constant B₂ - Constant value
 16. [B4]                <Constant value>        [B4]                                          1.0   Brun's constant for prime quadruplets - Mathematical constant B₄ - Constant value
 17. [BN'L]              <Constant value>        [BN'L]                                        1.0   de Bruijn-Newman constant - Mathematical constant Λ - Constant value
 18. [Kat]               <Constant value>        [Kat]                                         1.0   Catalan's constant - Mathematical constant G - Constant value
 19. [K*]                <Constant value>        [K*]                                          1.0   Landau-Ramanujan constant - Mathematical constant b - Constant value
 20. [K.]                <Constant value>        [K.]                                          1.0   Viswanath's constant - Mathematical constant V - Constant value
 21. [B'L]               <Constant value>        [B'L]                                         1.0   Legendre's constant - Mathematical constant B - Constant value
 22. [RS'm]              <Constant value>        [RS'm]                                        1.0   Ramanujan-Soldner constant - Mathematical constant μ - Constant value
 23. [EB'e]              <Constant value>        [EB'e]                                        1.0   Erdos-Borwein constant - Mathematical constant E - Constant value
 24. [Bern]              <Constant value>        [Bern]                                        1.0   Bernstein's constant - Mathematical constant β - Constant value
 25. [GKW'l]             <Constant value>        [GKW'l]                                       1.0   Gauss-Kuzmin-Wirsing constant - Mathematical constant λ - Constant value
 26. [HSM's]             <Constant value>        [HSM's]                                       1.0   Hafner-Sarnak-McCurley constant - Mathematical constant σ - Constant value
 27. [lm]                <Constant value>        [lm]                                          1.0   Golomb-Dickman constant - Mathematical constant λ - Constant value
 28. [Cah]               <Constant value>        [Cah]                                         1.0   Cahen's constant - Mathematical constant C - Constant value
 29. [Ll]                <Constant value>        [Ll]                                          1.0   Laplace limit constant - Mathematical constant - Constant value
 30. [AG]                <Constant value>        [AG]                                          1.0   Alladi-Grinstead constant - Mathematical constant - Constant value
 31. [L*]                <Constant value>        [L*]                                          1.0   Lengyel's constant - Mathematical constant Λ - Constant value
 32. [L.]                <Constant value>        [L.]                                          1.0   Levy's constant - Mathematical constant - Constant value
 33. [Dz3]               <Constant value>        [Dz3]                                         1.0   Apery's constant - Mathematical constant ζ(3) - Constant value
 34. [A3n]               <Constant value>        [A3n]                                         1.0   Mills' constant - Mathematical constant A - Constant value
 35. [Bh]                <Constant value>        [Bh]                                          1.0   Backhouse's constant - Mathematical constant B - Constant value
 36. [Pt]                <Constant value>        [Pt]                                          1.0   Porter's constant - Mathematical constant C - Constant value
 37. [L2]                <Constant value>        [L2]                                          1.0   Lieb's square ice constant - Mathematical constant - Constant value
 38. [Nv]                <Constant value>        [Nv]                                          1.0   Niven's constant - Mathematical constant C - Constant value
 39. [Ks]                <Constant value>        [Ks]                                          1.0   Sierpinski's constant - Mathematical constant K - Constant value
 40. [Kh]                <Constant value>        [Kh]                                          1.0   Khinchin's constant - Mathematical constant K₀ - Constant value
 41. [FR]                <Constant value>        [FR]                                          1.0   Fransen-Robinson constant - Mathematical constant F - Constant value
 42. [La]                <Constant value>        [La]                                          1.0   Landau's constant - Mathematical constant L - Constant value
 43. [P2]                <Constant value>        [P2]                                          1.0   Parabolic constant - Mathematical constant P - Constant value
 44. [Om]                <Constant value>        [Om]                                          1.0   Omega constant - Mathematical constant Ω - Constant value
 45. [MRB]               <Constant value>        [MRB]                                         1.0   MRB constant - Mathematical constant S - Constant value
 46. [li2]               <Constant value>        [li2]                                         2.3   Logarithmic integral at point 2 - Mathematical constant li(2) - Constant value
 47. [EG]                <Constant value>        [EG]                                          2.3   Gompertz constant - Mathematical constant δ - Constant value
 48. [c]                 <Constant value>        [c]                                           4.0   Light speed in vacuum - Physical constant c [m/s] (m=1, s=1) - Constant value
 49. [G.]                <Constant value>        [G.]                                          4.0   Gravitational constant - Physical constant G (m=1, kg=1, s=1) - Constant value
 50. [g]                 <Constant value>        [g]                                           4.0   Gravitational acceleration on Earth - Physical constant g [m/s²] (m=1, s=1) - Constant value
 51. [hP]                <Constant value>        [hP]                                          4.0   Planck constant - Physical constant h (m=1, kg=1, s=1) - Constant value
 52. [h-]                <Constant value>        [h-]                                          4.0   Reduced Planck constant (Dirac constant) - Physical constant ħ (m=1, kg=1, s=1) - Constant value
 53. [lP]                <Constant value>        [lP]                                          4.0   Planck length - Physical constant lᵖ [m] (m=1) - Constant value
 54. [mP]                <Constant value>        [mP]                                          4.0   Planck mass - Physical constant mᵖ [kg] (kg=1) - Constant value
 55. [tP]                <Constant value>        [tP]                                          4.0   Planck time - Physical constant tᵖ [s] (s=1) - Constant value
 56. [ly]                <Constant value>        [ly]                                          4.0   Light year - Astronomical constant ly [m] (m=1) - Constant value
 57. [au]                <Constant value>        [au]                                          4.0   Astronomical unit - Astronomical constant au, AU [m] (m=1) - Constant value
 58. [pc]                <Constant value>        [pc]                                          4.0   Parsec - Astronomical constant pc [m] (m=1) - Constant value
 59. [kpc]               <Constant value>        [kpc]                                         4.0   Kiloparsec - Astronomical constant kpc [m] (m=1) - Constant value
 60. [Earth-R-eq]        <Constant value>        [Earth-R-eq]                                  4.0   Earth equatorial radius - Astronomical constant Rª⊕ [m] (m=1) - Constant value
 61. [Earth-R-po]        <Constant value>        [Earth-R-po]                                  4.0   Earth polar radius - Astronomical constant Rᵇ⊕ [m] (m=1) - Constant value
 62. [Earth-R]           <Constant value>        [Earth-R]                                     4.0   Earth mean radius - Astronomical constant R⊕ (m=1) - Constant value
 63. [Earth-M]           <Constant value>        [Earth-M]                                     4.0   Earth mass - Astronomical constant M⊕ [kg] (kg=1) - Constant value
 64. [Earth-D]           <Constant value>        [Earth-D]                                     4.0   Earth-Sun distance - Astronomical constant - Semi major axis [m] (m=1) - Constant value
 65. [Moon-R]            <Constant value>        [Moon-R]                                      4.0   Moon mean radius - Astronomical constant [m] (m=1) - Constant value
 66. [Moon-M]            <Constant value>        [Moon-M]                                      4.0   Moon mass - Astronomical constant [kg] (kg=1) - Constant value
 67. [Moon-D]            <Constant value>        [Moon-D]                                      4.0   Moon-Earth distance - Astronomical constant - Semi major axis [m] (m=1) - Constant value
 68. [Solar-R]           <Constant value>        [Solar-R]                                     4.0   Solar mean radius - Astronomical constant R☉ [m] (m=1) - Constant value
 69. [Solar-M]           <Constant value>        [Solar-M]                                     4.0   Solar mass - Astronomical constant M☉ [kg] (kg=1) - Constant value
 70. [Mercury-R]         <Constant value>        [Mercury-R]                                   4.0   Mercury mean radius - Astronomical constant [m] (m=1) - Constant value
 71. [Mercury-M]         <Constant value>        [Mercury-M]                                   4.0   Mercury mass - Astronomical constant [kg] (kg=1) - Constant value
 72. [Mercury-D]         <Constant value>        [Mercury-D]                                   4.0   Mercury-Sun distance - Astronomical constant - Semi major axis [m] (m=1) - Constant value
 73. [Venus-R]           <Constant value>        [Venus-R]                                     4.0   Venus mean radius - Astronomical constant [m] (m=1) - Constant value
 74. [Venus-M]           <Constant value>        [Venus-M]                                     4.0   Venus mass - Astronomical constant [kg] (kg=1) - Constant value
 75. [Venus-D]           <Constant value>        [Venus-D]                                     4.0   Venus-Sun distance - Astronomical constant - Semi major axis [m] (m=1) - Constant value
 76. [Mars-R]            <Constant value>        [Mars-R]                                      4.0   Mars mean radius - Astronomical constant [m] (m=1) - Constant value
 77. [Mars-M]            <Constant value>        [Mars-M]                                      4.0   Mars mass - Astronomical constant [kg] (kg=1) - Constant value
 78. [Mars-D]            <Constant value>        [Mars-D]                                      4.0   Mars-Sun distance - Astronomical constant - Semi major axis [m] (m=1) - Constant value
 79. [Jupiter-R]         <Constant value>        [Jupiter-R]                                   4.0   Jupiter mean radius - Astronomical constant [m] (m=1) - Constant value
 80. [Jupiter-M]         <Constant value>        [Jupiter-M]                                   4.0   Jupiter mass - Astronomical constant [kg] (kg=1) - Constant value
 81. [Jupiter-D]         <Constant value>        [Jupiter-D]                                   4.0   Jupiter-Sun distance - Astronomical constant - Semi major axis [m] (m=1) - Constant value
 82. [Saturn-R]          <Constant value>        [Saturn-R]                                    4.0   Saturn mean radius - Astronomical constant [m] (m=1) - Constant value
 83. [Saturn-M]          <Constant value>        [Saturn-M]                                    4.0   Saturn mass - Astronomical constant [kg] (kg=1) - Constant value
 84. [Saturn-D]          <Constant value>        [Saturn-D]                                    4.0   Saturn-Sun distance - Astronomical constant - Semi major axis [m] (m=1) - Constant value
 85. [Uranus-R]          <Constant value>        [Uranus-R]                                    4.0   Uranus mean radius - Astronomical constant [m] (m=1) - Constant value
 86. [Uranus-M]          <Constant value>        [Uranus-M]                                    4.0   Uranus mass - Astronomical constant [kg] (kg=1) - Constant value
 87. [Uranus-D]          <Constant value>        [Uranus-D]                                    4.0   Uranus-Sun distance - Astronomical constant - Semi major axis [m] (m=1) - Constant value
 88. [Neptune-R]         <Constant value>        [Neptune-R]                                   4.0   Neptune mean radius - Astronomical constant [m] (m=1) - Constant value
 89. [Neptune-M]         <Constant value>        [Neptune-M]                                   4.0   Neptune mass - Astronomical constant [kg] (kg=1) - Constant value
 90. [Neptune-D]         <Constant value>        [Neptune-D]                                   4.0   Neptune-Sun distance - Astronomical constant - Semi major axis [m] (m=1) - Constant value
 91. [true]              <Constant value>        [true]                                        4.1   Boolean True represented as 1 (true=1) - Constant value
 92. [false]             <Constant value>        [false]                                       4.1   Boolean False represented as 0 (false=0) - Constant value
 93. [NaN]               <Constant value>        [NaN]                                         4.1   Not-a-Number - Constant value
[mXparser-v.5.2.1] 
Nuget – Package Manager (C#, F#, Visual Basic, …)

Install-Package MathParser.org-mXparser -Version 6.1.0

Nuget – .NET CLI

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

Nuget – Package Reference

<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

My other creative spaces

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