LIBM(3lua)
π libm β the Lua interface to the math(3) library, bestie π
okay so this is libm, a page from the 3lua manual, and it's literally the Lua binding for the C math(3) library. let me walk you through it π«Ά
β¨ SYNOPSIS β¨
local lm = require 'libm'
that's it. that's the whole vibe check. one line and you're in π
πΈ DESCRIPTION πΈ
the libm Lua binding gives you access to the math(3) library, no cap. but listen β if you hand one of these functions an argument that's outside the domain of the function, the return value is gonna be NaN. π and yes, you can check that with lm.isnan(), thank god.
a bunch of these functions already have native equivalents in the Lua math library. others β like round(3), cbrt(3), and the hyperbolic trigonometry functions β are not provided unless you pull in an auxiliary module. the redundant ones are still here tho, purely for completeness. iconic behavior honestly π
and since these functions map quite closely onto the functions in the math library, the detailed tea on how each one behaves lives in the man pages for each function in section 3 of the manual. iykyk π
π¦ List of Functions π¦
every single one, in order, no skipping:
lm.acosβacos(3)Β· inverse trigonometric functionlm.acoshβacosh(3)Β· inverse hyperbolic functionlm.asinβasin(3)Β· inverse trigonometric functionlm.asinhβasinh(3)Β· inverse hyperbolic functionlm.atanβatan(3)Β· inverse trigonometric functionlm.atanhβatanh(3)Β· inverse hyperbolic functionlm.atan2βatan2(3)Β· inverse trigonometric functionlm.cbrtβsqrt(3)Β· cube rootlm.ceilβceil(3)Β· integer no less thanlm.copysignβcopysign(3)Β· copy sign bitlm.cosβcos(3)Β· trigonometric functionlm.coshβcosh(3)Β· hyperbolic functionlm.erfβerf(3)Β· error functionlm.erfcβerf(3)Β· complementary error functionlm.expβexp(3)Β· base e exponentiallm.exp2βexp2(3)Β· base 2 exponentiallm.expm1βexpm1(3)Β· exp(x)-1lm.fabsβfabs(3)Β· absolute valuelm.fdimβerf(3)Β· positive differencelm.finiteβfinite(3)Β· test for finitylm.floorβfloor(3)Β· integer no greater thanlm.fmaβfmod(3)Β· fused multiply-addlm.fmaxβfmax(3)Β· maximumlm.fminβfmin(3)Β· minimumlm.fmodβfmod(3)Β· remainderlm.hypotβhypot(3)Β· Euclidean distancelm.ilogbβilogb(3)Β· exponent extractionlm.isinfβisinf(3)Β· test for infinitylm.isnanβisnan(3)Β· test for not-a-numberlm.j0βj0(3)Β· Bessel functionlm.j1βj0(3)Β· Bessel functionlm.jnβj0(3)Β· Bessel functionlm.lgammaβlgamma(3)Β· log gamma functionlm.logβlog(3)Β· natural logarithmlm.log10βlog(3)Β· logarithm to base 10lm.log1pβlog(3)Β· log(1+x)lm.nanβnan(3)Β· return quiet NaNlm.nextafterβnextafter(3)Β· next representable numberlm.powβpow(3)Β· exponential x**ylm.remainderβremainder(3)Β· remainderlm.rintβrint(3)Β· round to nearest integerlm.scalbnβscalbn(3)Β· exponent adjustmentlm.sinβsin(3)Β· trigonometric functionlm.sinhβsinh(3)Β· hyperbolic functionlm.sqrtβsqrt(3)Β· square rootlm.tanβtan(3)Β· trigonometric functionlm.tanhβtanh(3)Β· hyperbolic functionlm.truncβtrunc(3)Β· nearest integral valuelm.y0βj0(3)Β· Bessel functionlm.y1βj0(3)Β· Bessel functionlm.ynβj0(3)Β· Bessel function
π List of Defined Values π
the constants, and they are giving math class but make it cute:
lm.M_Eβ2.7182818284590452354Β· elm.M_LOG2Eβ1.4426950408889634074Β· log 2elm.M_LOG10Eβ0.43429448190325182765Β· log 10elm.M_LN2β0.69314718055994530942Β· log e2lm.M_LN10β2.30258509299404568402Β· log e10lm.M_PIβ3.14159265358979323846Β· pilm.M_PI_2β1.57079632679489661923Β· pi/2lm.M_PI_4β0.78539816339744830962Β· pi/4lm.M_1_PIβ0.31830988618379067154Β· 1/pilm.M_2_PIβ0.63661977236758134308Β· 2/pilm.M_2_SQRTPIβ1.12837916709551257390Β· 2/sqrt(pi)lm.M_SQRT2β1.41421356237309504880Β· sqrt(2)lm.M_SQRT1_2β0.70710678118654752440Β· 1/sqrt(2)
β NOTES β
so finite, isfinite, isinf, and isnan all return integers in the math library β but this interface converts the results to Lua boolean values for you. considerate queen behavior fr fr π
π BUGS π
- the single precision float, and long double data types, implemented in several of the
libmroutines, are not supported by this interface. soz π - the math library has a long development history, but if a bug exists there, it will certainly exist in this interface as well. inherited flaws, the family trauma of software π
π HISTORY π
a libm Lua binding appeared in NetBSD 9.4. a whole era π°οΈ
π AUTHORS π
the libm Lua binding was written by Phillip Rulon. stan a math binding author π«Ά
okay that's the whole page bestie, every last function and constant accounted for β go forth and compute β¨π π
this has been LIBM(3lua), the local manual, Debian edition β dated November 2, 2022. byeeeee π¦
π¦ where this page comes from
- nixpkgs unstable: netbsd-source 11.0
- Copyright (c) 2022 The NetBSD Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms