Home | History | Annotate | Line # | Download | only in libm
lualibm.lua revision 1.1
      1  1.1  christos #!/usr/bin/lua
      2  1.1  christos 
      3  1.1  christos local lm = require("libm")
      4  1.1  christos 
      5  1.1  christos local fmtf = "%-24s%+2.13f"
      6  1.1  christos local fmti = "%-24s%d"
      7  1.1  christos 
      8  1.1  christos local function test(s,x)
      9  1.1  christos    print(string.format(fmtf, s, x))
     10  1.1  christos end
     11  1.1  christos 
     12  1.1  christos local function testb(s,x)
     13  1.1  christos    print(string.format(fmti, s, x and 1 or 0))
     14  1.1  christos end
     15  1.1  christos 
     16  1.1  christos test("M_E",lm.M_E);
     17  1.1  christos test("M_LOG2E",lm.M_LOG2E)
     18  1.1  christos test("M_LOG10E",lm.M_LOG10E)
     19  1.1  christos test("M_LN2",lm.M_LN2)
     20  1.1  christos test("M_LN10",lm.M_LN10)
     21  1.1  christos test("M_PI",lm.M_PI)
     22  1.1  christos test("M_PI_2",lm.M_PI_2)
     23  1.1  christos test("M_PI_4",lm.M_PI_4)
     24  1.1  christos test("M_1_PI",lm.M_1_PI)
     25  1.1  christos test("M_2_PI",lm.M_2_PI)
     26  1.1  christos test("M_2_SQRTPI",lm.M_2_SQRTPI)
     27  1.1  christos test("M_SQRT2",lm.M_SQRT2)
     28  1.1  christos test("M_SQRT1_2",lm.M_SQRT1_2)
     29  1.1  christos 
     30  1.1  christos test("cos(M_PI_2)", lm.cos(lm.M_PI_2))
     31  1.1  christos test("acos(cos(M_PI_2))",lm.acos(lm.cos(lm.M_PI_2)))
     32  1.1  christos test("cosh(M_SQRT1_2)",lm.cosh(lm.M_SQRT1_2))
     33  1.1  christos test("acosh(cosh(M_SQRT1_2))",lm.acosh(lm.cosh(lm.M_SQRT1_2)))
     34  1.1  christos test("sin(M_PI_2)",lm.sin(lm.M_PI_2))
     35  1.1  christos test("asin(sin(M_PI_2))",lm.asin(lm.sin(lm.M_PI_2)))
     36  1.1  christos test("sinh(M_PI_2)",lm.sinh(lm.M_PI_2))
     37  1.1  christos test("asinh(sinh(M_PI_2))",lm.asinh(lm.sinh(lm.M_PI_2)))
     38  1.1  christos test("tan(M_SQRT2)",lm.tan(lm.M_SQRT2))
     39  1.1  christos test("atan(tan(M_SQRT2))",lm.atan(lm.tan(lm.M_SQRT2)))
     40  1.1  christos test("tanh(M_SQRT2)",lm.tanh(lm.M_SQRT2))
     41  1.1  christos test("atanh(tanh(M_SQRT2))",lm.atanh(lm.tanh(lm.M_SQRT2)))
     42  1.1  christos test("atan2(M_SQRT2,M_SQRT2)",lm.atan2(lm.M_SQRT2,lm.M_SQRT2))
     43  1.1  christos test("cbrt(8.0)",lm.cbrt(8.0))
     44  1.1  christos test("ceil(M_PI)",lm.ceil(lm.M_PI))
     45  1.1  christos test("ceil(M_E)",lm.ceil(lm.M_E))
     46  1.1  christos test("copysign(-2.0,10.0)",lm.copysign(-2.0,10.0))
     47  1.1  christos test("copysign(2.0,-10.0)",lm.copysign(2.0,-10.0))
     48  1.1  christos test("erf(M_SQRT1_2)",lm.erf(lm.M_SQRT1_2))
     49  1.1  christos test("erfc(M_SQRT1_2)",lm.erfc(lm.M_SQRT1_2))
     50  1.1  christos test("exp(M_PI_4)",lm.exp(lm.M_PI_4))
     51  1.1  christos test("exp2(3.0)",lm.exp2(3.0))
     52  1.1  christos test("expm1(M_PI_4)",lm.expm1(lm.M_PI_4))
     53  1.1  christos test("fabs(-M_SQRT2)",lm.fabs(-lm.M_SQRT2))
     54  1.1  christos test("fabs(M_SQRT2)",lm.fabs(lm.M_SQRT2))
     55  1.1  christos test("fdim(M_PI,M_PI_2)",lm.fdim(lm.M_PI,lm.M_PI_2))
     56  1.1  christos test("fdim(M_PI,-M_PI_2)",lm.fdim(lm.M_PI,-lm.M_PI_2))
     57  1.1  christos testb("finite(1.0/0.0)",lm.finite(1.0/0.0))
     58  1.1  christos test("floor(M_PI)",lm.floor(lm.M_PI))
     59  1.1  christos test("floor(M_E)",lm.floor(lm.M_E))
     60  1.1  christos test("fma(M_PI,M_E,M_SQRT2)",lm.fma(lm.M_PI,lm.M_E,lm.M_SQRT2))
     61  1.1  christos test("fmax(M_PI,M_E)",lm.fmax(lm.M_PI,lm.M_E))
     62  1.1  christos test("fmin(M_PI,M_E)",lm.fmin(lm.M_PI,lm.M_E))
     63  1.1  christos test("fmod(100.5,10.0)",lm.fmod(100.5,10.0))
     64  1.1  christos test("gamma(5.0)",lm.gamma(5.0))
     65  1.1  christos test("hypot(3.0,4.0)",lm.hypot(3.0,4.0))
     66  1.1  christos print(string.format(fmti, "ilogb(10.0)", lm.ilogb(10.0)))
     67  1.1  christos testb("isinf(1.0/0.0)",lm.isinf(1.0/0.0))
     68  1.1  christos testb("isnan(log(-1.0))",lm.isnan(lm.log(-1.0)))
     69  1.1  christos test("j0(M_PI)",lm.j0(lm.M_PI))
     70  1.1  christos test("j1(M_PI)",lm.j1(lm.M_PI))
     71  1.1  christos test("jn(3,M_PI)",lm.jn(3,lm.M_PI))
     72  1.1  christos test("lgamma(M_PI)",lm.lgamma(lm.M_PI))
     73  1.1  christos test("log(M_E)",lm.log(lm.M_E))
     74  1.1  christos test("log10(100.0)",lm.log10(100.0))
     75  1.1  christos test("log1p(M_PI)",lm.log1p(lm.M_PI))
     76  1.1  christos test("nan(\"\")",lm.nan(""))
     77  1.1  christos test("nextafter(1.0e-14,1.0)",lm.nextafter(1.0e-14,1.0))
     78  1.1  christos test("pow(M_SQRT2,2.0)",lm.pow(lm.M_SQRT2,2.0))
     79  1.1  christos test("remainder(M_PI,M_E)",lm.remainder(lm.M_PI,lm.M_E))
     80  1.1  christos test("rint(M_PI)",lm.rint(lm.M_PI))
     81  1.1  christos test("rint(M_E)",lm.rint(lm.M_E))
     82  1.1  christos print(string.format(fmtf, "scalbn(1.0,2)", lm.scalbn(1.0,2)))
     83  1.1  christos test("sin(M_PI_4)",lm.sin(lm.M_PI_4))
     84  1.1  christos test("sinh(M_PI_4)",lm.sinh(lm.M_PI_4))
     85  1.1  christos test("sqrt(9.0)",lm.sqrt(9.0))
     86  1.1  christos test("tan(M_PI_4)",lm.tan(lm.M_PI_4))
     87  1.1  christos test("tanh(M_PI_4)",lm.tanh(lm.M_PI_4))
     88  1.1  christos test("trunc(M_PI)",lm.trunc(lm.M_PI))
     89  1.1  christos test("trunc(M_E)",lm.trunc(lm.M_E))
     90  1.1  christos test("y0(M_PI)",lm.y0(lm.M_PI))
     91  1.1  christos test("y1(M_PI)",lm.y1(lm.M_PI))
     92  1.1  christos test("yn(3,M_PI)",lm.yn(3,lm.M_PI))
     93