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 ofaasin(a)- arc sine ofaatan(a)- arc tangent ofacosh(a)- hyperbolic cosine ofasinh(a)- hyperbolic sine ofatanh(a)- hyperbolic tangent ofaatan2(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) ofalog(a,b)- baseblogarithm ofa(shortcut forlog(a)/log(b))
log10(a)- base 10 logarithm ofalog1p(a)- natural logarithm ofa+1ceil(a)- smallest value that is greater than or equal toaand is equal to a mathematical integerfloor(a)- largest value that is less than or equal toaand is equal to a mathematical integertrunc(a)-awith the fractional part removed, leaving the integer partround(a)- closest value toa, with ties rounding to positive infinityrint(a)- value that is closest toaand is equal to a mathematical integer; for.5values 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)-araised to the power ofb(same asa^b)sqrt(a)- positive square root ofacbrt(a)- cube root ofaroot(a,b)-broot ofa(shortcut forpow(a,1/b))hypot- hypotenusehypot(a,b)- hypotenuse ofaandbwithout 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 ofaexpm1(a)- E raised to the power ofa, minus1to_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 ofanext_down(a)- floating-point value adjacent toain the direction of negative infinitynext_up(a)- floating-point value adjacent toain the direction of positive infinitynext_after(a,b)- floating-point number adjacent toain the direction ofbsignum(a)- signum function ofaulp(a)- size of an ulp ofaieee_remainder(a,b)- remainder operation%on two arguments as prescribed by the IEEE 754 standardcopy_sign(a,b)-awith the sign ofbfma(a,b,c)- exact product ofa*b+crounded 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 <= 0for negativea)random(a,b)- random numbera <= x < b
rng_choice(a,b...)- random choose between multiple numberslog_gamma(a)- logarithm of gamma function ofagamma(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")
}