Home | History | Annotate | Line # | Download | only in libm
      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.2       rin 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.2       rin 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.2       rin test("M_E", lm.M_E);
     17  1.2       rin test("M_LOG2E", lm.M_LOG2E)
     18  1.2       rin test("M_LOG10E", lm.M_LOG10E)
     19  1.2       rin test("M_LN2", lm.M_LN2)
     20  1.2       rin test("M_LN10", lm.M_LN10)
     21  1.2       rin test("M_PI", lm.M_PI)
     22  1.2       rin test("M_PI_2", lm.M_PI_2)
     23  1.2       rin test("M_PI_4", lm.M_PI_4)
     24  1.2       rin test("M_1_PI", lm.M_1_PI)
     25  1.2       rin test("M_2_PI", lm.M_2_PI)
     26  1.2       rin test("M_2_SQRTPI", lm.M_2_SQRTPI)
     27  1.2       rin test("M_SQRT2", lm.M_SQRT2)
     28  1.2       rin 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.2       rin test("acos(cos(M_PI_2))", lm.acos(lm.cos(lm.M_PI_2)))
     32  1.2       rin test("cosh(M_SQRT1_2)", lm.cosh(lm.M_SQRT1_2))
     33  1.2       rin test("acosh(cosh(M_SQRT1_2))", lm.acosh(lm.cosh(lm.M_SQRT1_2)))
     34  1.2       rin test("sin(M_PI_2)", lm.sin(lm.M_PI_2))
     35  1.2       rin test("asin(sin(M_PI_2))", lm.asin(lm.sin(lm.M_PI_2)))
     36  1.2       rin test("sinh(M_PI_2)", lm.sinh(lm.M_PI_2))
     37  1.2       rin test("asinh(sinh(M_PI_2))", lm.asinh(lm.sinh(lm.M_PI_2)))
     38  1.2       rin test("tan(M_SQRT2)", lm.tan(lm.M_SQRT2))
     39  1.2       rin test("atan(tan(M_SQRT2))", lm.atan(lm.tan(lm.M_SQRT2)))
     40  1.2       rin test("tanh(M_SQRT2)", lm.tanh(lm.M_SQRT2))
     41  1.2       rin test("atanh(tanh(M_SQRT2))", lm.atanh(lm.tanh(lm.M_SQRT2)))
     42  1.2       rin test("atan2(M_SQRT2, M_SQRT2)", lm.atan2(lm.M_SQRT2, lm.M_SQRT2))
     43  1.2       rin test("cbrt(8.0)", lm.cbrt(8.0))
     44  1.2       rin test("ceil(M_PI)", lm.ceil(lm.M_PI))
     45  1.2       rin test("ceil(M_E)", lm.ceil(lm.M_E))
     46  1.2       rin test("copysign(-2.0, 10.0)", lm.copysign(-2.0, 10.0))
     47  1.2       rin test("copysign(2.0, -10.0)", lm.copysign(2.0, -10.0))
     48  1.2       rin test("erf(M_SQRT1_2)", lm.erf(lm.M_SQRT1_2))
     49  1.2       rin test("erfc(M_SQRT1_2)", lm.erfc(lm.M_SQRT1_2))
     50  1.2       rin test("exp(M_PI_4)", lm.exp(lm.M_PI_4))
     51  1.2       rin test("exp2(3.0)", lm.exp2(3.0))
     52  1.2       rin test("expm1(M_PI_4)", lm.expm1(lm.M_PI_4))
     53  1.2       rin test("fabs(-M_SQRT2)", lm.fabs(-lm.M_SQRT2))
     54  1.2       rin test("fabs(M_SQRT2)", lm.fabs(lm.M_SQRT2))
     55  1.2       rin test("fdim(M_PI, M_PI_2)", lm.fdim(lm.M_PI, lm.M_PI_2))
     56  1.2       rin test("fdim(M_PI, -M_PI_2)", lm.fdim(lm.M_PI, -lm.M_PI_2))
     57  1.2       rin testb("finite(1.0 / 0.0)", lm.finite(1.0 / 0.0))
     58  1.2       rin test("floor(M_PI)", lm.floor(lm.M_PI))
     59  1.2       rin test("floor(M_E)", lm.floor(lm.M_E))
     60  1.2       rin test("fma(M_PI, M_E, M_SQRT2)", lm.fma(lm.M_PI, lm.M_E, lm.M_SQRT2))
     61  1.2       rin test("fmax(M_PI, M_E)", lm.fmax(lm.M_PI, lm.M_E))
     62  1.2       rin test("fmin(M_PI, M_E)", lm.fmin(lm.M_PI, lm.M_E))
     63  1.2       rin test("fmod(100.5, 10.0)", lm.fmod(100.5, 10.0))
     64  1.2       rin test("gamma(5.0)", lm.gamma(5.0))
     65  1.2       rin 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.2       rin testb("isinf(1.0 / 0.0)", lm.isinf(1.0 / 0.0))
     68  1.2       rin testb("isnan(log(-1.0))", lm.isnan(lm.log(-1.0)))
     69  1.2       rin test("j0(M_PI)", lm.j0(lm.M_PI))
     70  1.2       rin test("j1(M_PI)", lm.j1(lm.M_PI))
     71  1.2       rin test("jn(3, M_PI)", lm.jn(3, lm.M_PI))
     72  1.2       rin test("lgamma(M_PI)", lm.lgamma(lm.M_PI))
     73  1.2       rin test("log(M_E)", lm.log(lm.M_E))
     74  1.2       rin test("log10(100.0)", lm.log10(100.0))
     75  1.2       rin test("log1p(M_PI)", lm.log1p(lm.M_PI))
     76  1.2       rin test("nan(\"\")", lm.nan(""))
     77  1.3  christos -- XXX vax test("nextafter(1.0e-14, 1.0)", lm.nextafter(1.0e-14, 1.0))
     78  1.2       rin test("pow(M_SQRT2, 2.0)", lm.pow(lm.M_SQRT2, 2.0))
     79  1.2       rin test("remainder(M_PI, M_E)", lm.remainder(lm.M_PI, lm.M_E))
     80  1.2       rin test("rint(M_PI)", lm.rint(lm.M_PI))
     81  1.2       rin test("rint(M_E)", lm.rint(lm.M_E))
     82  1.2       rin print(string.format(fmtf, "scalbn(1.0, 2)", lm.scalbn(1.0, 2)))
     83  1.2       rin test("sin(M_PI_4)", lm.sin(lm.M_PI_4))
     84  1.2       rin test("sinh(M_PI_4)", lm.sinh(lm.M_PI_4))
     85  1.2       rin test("sqrt(9.0)", lm.sqrt(9.0))
     86  1.2       rin test("tan(M_PI_4)", lm.tan(lm.M_PI_4))
     87  1.2       rin test("tanh(M_PI_4)", lm.tanh(lm.M_PI_4))
     88  1.2       rin test("trunc(M_PI)", lm.trunc(lm.M_PI))
     89  1.2       rin test("trunc(M_E)", lm.trunc(lm.M_E))
     90  1.2       rin test("y0(M_PI)", lm.y0(lm.M_PI))
     91  1.2       rin test("y1(M_PI)", lm.y1(lm.M_PI))
     92  1.2       rin test("yn(3, M_PI)", lm.yn(3, lm.M_PI))
     93