LIBM(3lua)

πŸ“¦ version 11.0, in nixpkgs unstable

πŸ’– 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 function
  • lm.acosh β€” acosh(3) Β· inverse hyperbolic function
  • lm.asin β€” asin(3) Β· inverse trigonometric function
  • lm.asinh β€” asinh(3) Β· inverse hyperbolic function
  • lm.atan β€” atan(3) Β· inverse trigonometric function
  • lm.atanh β€” atanh(3) Β· inverse hyperbolic function
  • lm.atan2 β€” atan2(3) Β· inverse trigonometric function
  • lm.cbrt β€” sqrt(3) Β· cube root
  • lm.ceil β€” ceil(3) Β· integer no less than
  • lm.copysign β€” copysign(3) Β· copy sign bit
  • lm.cos β€” cos(3) Β· trigonometric function
  • lm.cosh β€” cosh(3) Β· hyperbolic function
  • lm.erf β€” erf(3) Β· error function
  • lm.erfc β€” erf(3) Β· complementary error function
  • lm.exp β€” exp(3) Β· base e exponential
  • lm.exp2 β€” exp2(3) Β· base 2 exponential
  • lm.expm1 β€” expm1(3) Β· exp(x)-1
  • lm.fabs β€” fabs(3) Β· absolute value
  • lm.fdim β€” erf(3) Β· positive difference
  • lm.finite β€” finite(3) Β· test for finity
  • lm.floor β€” floor(3) Β· integer no greater than
  • lm.fma β€” fmod(3) Β· fused multiply-add
  • lm.fmax β€” fmax(3) Β· maximum
  • lm.fmin β€” fmin(3) Β· minimum
  • lm.fmod β€” fmod(3) Β· remainder
  • lm.hypot β€” hypot(3) Β· Euclidean distance
  • lm.ilogb β€” ilogb(3) Β· exponent extraction
  • lm.isinf β€” isinf(3) Β· test for infinity
  • lm.isnan β€” isnan(3) Β· test for not-a-number
  • lm.j0 β€” j0(3) Β· Bessel function
  • lm.j1 β€” j0(3) Β· Bessel function
  • lm.jn β€” j0(3) Β· Bessel function
  • lm.lgamma β€” lgamma(3) Β· log gamma function
  • lm.log β€” log(3) Β· natural logarithm
  • lm.log10 β€” log(3) Β· logarithm to base 10
  • lm.log1p β€” log(3) Β· log(1+x)
  • lm.nan β€” nan(3) Β· return quiet NaN
  • lm.nextafter β€” nextafter(3) Β· next representable number
  • lm.pow β€” pow(3) Β· exponential x**y
  • lm.remainder β€” remainder(3) Β· remainder
  • lm.rint β€” rint(3) Β· round to nearest integer
  • lm.scalbn β€” scalbn(3) Β· exponent adjustment
  • lm.sin β€” sin(3) Β· trigonometric function
  • lm.sinh β€” sinh(3) Β· hyperbolic function
  • lm.sqrt β€” sqrt(3) Β· square root
  • lm.tan β€” tan(3) Β· trigonometric function
  • lm.tanh β€” tanh(3) Β· hyperbolic function
  • lm.trunc β€” trunc(3) Β· nearest integral value
  • lm.y0 β€” j0(3) Β· Bessel function
  • lm.y1 β€” j0(3) Β· Bessel function
  • lm.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 Β· e
  • lm.M_LOG2E β€” 1.4426950408889634074 Β· log 2e
  • lm.M_LOG10E β€” 0.43429448190325182765 Β· log 10e
  • lm.M_LN2 β€” 0.69314718055994530942 Β· log e2
  • lm.M_LN10 β€” 2.30258509299404568402 Β· log e10
  • lm.M_PI β€” 3.14159265358979323846 Β· pi
  • lm.M_PI_2 β€” 1.57079632679489661923 Β· pi/2
  • lm.M_PI_4 β€” 0.78539816339744830962 Β· pi/4
  • lm.M_1_PI β€” 0.31830988618379067154 Β· 1/pi
  • lm.M_2_PI β€” 0.63661977236758134308 Β· 2/pi
  • lm.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 libm routines, 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