Simple math evaluator. Supports constants, functions, variables. Evaluators code is based off Boann's answer on StackOverflow.
It should be noted that the lib uses Java's double
as its base number type, so it's rather fast.
That being said, it also means that calculations are affected by imprecision, so big numbers are a no-no.
Also, for performance reasons, EzMath throws no exceptions, so weird behaviour on invalid inputs is to be expected.
123
, -45.6
, 7.8E9
, 10.11E-12
1+2
, 3-4
, 5*6
, 7/8
, 9^10
, 11%12
(1+2)
, 3^(4 - 5.67)
, 89 / ((10*11)/121.3)
pi/2
, e^3
List of available constants
e
- Euler's number - the base of the natural logarithmspi
- the ratio of the circumference of a circle to its diametertau
- the ratio of the circumference of a circle to its radius (shortcut forpi*2
)infinity
- infinite valuenan
- not-a-number valuemax_value
- the largest finite value that can be used in calculationsmin_value
- the smallest positive value that can be used in calculationseuler
- Euler's (Euler-Mascheroni) constantphi
- the golden ratioln2
- natural logarithm of 2ln10
- natural logarithm of 10log2e
- base 2 logarithm of Elog10e
- base 10 logarithm of E
sin(123)
, sqrt(456)
, max(78,910,11)
List of available functions
max(a,b...)
- greater of specified valuesmin(a,b...)
- smaller of specified valuesavg(a,b...)
- average of specified valuescos(a)
- trigonometric cosine of an anglesin(a)
- trigonometric sine of an angletan(a)
- trigonometric tangent of an angleacos(a)
- arc cosine ofa
asin(a)
- arc sine ofa
atan(a)
- arc tangent ofa
cosh(a)
- hyperbolic cosine ofa
sinh(a)
- hyperbolic sine ofa
tanh(a)
- hyperbolic tangent ofa
atan2(a,b)
- angle theta from the conversion of rectangular coordinates x(b
), y(a
) to polar coordinates (r, theta)abs(a)
- absolute valuelog
- logarithmlog(a)
- natural logarithm (base E) ofa
log(a,b)
- baseb
logarithm ofa
(shortcut forlog(a)/log(b)
)
log10(a)
- base 10 logarithm ofa
log1p(a)
- natural logarithm ofa+1
ceil(a)
- smallest value that is greater than or equal toa
and is equal to a mathematical integerfloor(a)
- largest value that is less than or equal toa
and is equal to a mathematical integertrunc(a)
-a
with the fractional part removed, leaving the integer partround(a)
- closest value toa
, with ties rounding to positive infinityrint(a)
- value that is closest toa
and is equal to a mathematical integer; for.5
values rounds to closest even numberformat_float(a)
- round to the first two decimal places (shortcut fortrunc(a*100)/100
); very inaccurate for some numberspow(a,b)
-a
raised to the power ofb
(same asa^b
)sqrt(a)
- positive square root ofa
cbrt(a)
- cube root ofa
root(a,b)
-b
root ofa
(shortcut forpow(a,1/b)
)hypot
- hypotenusehypot(a,b)
- hypotenuse ofa
andb
without intermediate overflow or underflow (sqrt(a^2+b^2)
)hypot(a,b,c...)
- hypotenuse of lengths (shortcut forsqrt(a^2+b^2+c^2...)
)
raw_hypot(a,b...)
- hypotenuse of lengths with no square root operation (shortcut fora^2+b^2...
)exp(a)
- E raised to the power ofa
expm1(a)
- E raised to the power ofa
, minus1
to_degrees(a)
- angle measured in radians to approximately equivalent angle measured in degreesto_radians(a)
- angle measured in degrees to approximately equivalent angle measured in radiansget_exponent(a)
- unbiased exponent used in the representation ofa
next_down(a)
- floating-point value adjacent toa
in the direction of negative infinitynext_up(a)
- floating-point value adjacent toa
in the direction of positive infinitynext_after(a,b)
- floating-point number adjacent toa
in the direction ofb
signum(a)
- signum function ofa
ulp(a)
- size of an ulp ofa
ieee_remainder(a,b)
- remainder operation%
on two arguments as prescribed by the IEEE 754 standardcopy_sign(a,b)
-a
with the sign ofb
fma(a,b,c)
- exact product ofa*b+c
rounded oncescalb(a,b)
-a*2^round(b)
rounded as if performed by a single correctly rounded floating-point multiplyrandom
- random number generatorrandom(a)
- random number0 <= x < a
(ora < x <= 0
for negativea
)random(a,b)
- random numbera <= x < b
rng_choice(a,b...)
- random choose between multiple numberslog_gamma(a)
- logarithm of gamma function ofa
gamma(a)
- gamma function ofa
(shortcut forexp(log_gamma(a))
)
Versions in dependency sections may be outdated. Check the badge above for the latest one.
Add to repositories
<repository>
<id>glowing-ink</id>
<url>https://repo.glowing.ink/releases</url>
</repository>
Or for latest snapshots
<repository>
<id>glowing-ink</id>
<url>http://repo.glowing.ink/snapshots</url>
</repository>
Add to dependencies
<dependency>
<groupId>ink.glowing</groupId>
<artifactId>ezmath</artifactId>
<version>3.21</version>
</dependency>
repositories {
maven {
url = uri("https://repo.glowing.ink/releases")
// url = uri("https://repo.glowing.ink/snapshots")
}
}
dependencies {
implementation("ink.glowing:ezmath:3.21")
}