develooper Front page | perl.cvs.parrot | Postings from December 2008

[svn:parrot] r33443 - in trunk/languages/lua: src/lib src/pmc t

From:
fperrad
Date:
December 2, 2008 09:15
Subject:
[svn:parrot] r33443 - in trunk/languages/lua: src/lib src/pmc t
Message ID:
20081202171538.AE227CB9AF@x12.develooper.com
Author: fperrad
Date: Tue Dec  2 09:15:37 2008
New Revision: 33443

Modified:
   trunk/languages/lua/src/lib/mathx.pir
   trunk/languages/lua/src/pmc/luanumber.pmc
   trunk/languages/lua/t/mathx.t

Log:
[Lua] mathx
- add some function (need method in LuaNumber PMC)

Modified: trunk/languages/lua/src/lib/mathx.pir
==============================================================================
--- trunk/languages/lua/src/lib/mathx.pir	(original)
+++ trunk/languages/lua/src/lib/mathx.pir	Tue Dec  2 09:15:37 2008
@@ -53,6 +53,7 @@
 gamma
 hypot
 ilogb
+isfinite
 isinf
 isnan
 isnormal
@@ -88,267 +89,363 @@
 .end
 
 
-=item C<math.acosh ()>
-
-NOT YET IMPLEMENTED.
+=item C<math.acosh (x)>
 
 =cut
 
 .sub 'acosh'
+    .param pmc x :optional
     .param pmc extra :slurpy
-    not_implemented()
+    .local pmc res
+    lua_checknumber(1, x)
+    res = x.'acosh'()
+    .return (res)
 .end
 
 
-=item C<math.asinh ()>
-
-NOT YET IMPLEMENTED.
+=item C<math.asinh (x)>
 
 =cut
 
 .sub 'asinh'
+    .param pmc x :optional
     .param pmc extra :slurpy
-    not_implemented()
+    .local pmc res
+    lua_checknumber(1, x)
+    res = x.'asinh'()
+    .return (res)
 .end
 
 
-=item C<math.atanh ()>
-
-NOT YET IMPLEMENTED.
+=item C<math.atanh (x)>
 
 =cut
 
 .sub 'atanh'
+    .param pmc x :optional
     .param pmc extra :slurpy
-    not_implemented()
+    .local pmc res
+    lua_checknumber(1, x)
+    res = x.'atanh'()
+    .return (res)
 .end
 
 
-=item C<math.cbrt ()>
-
-NOT YET IMPLEMENTED.
+=item C<math.cbrt (x)>
 
 =cut
 
 .sub 'cbrt'
+    .param pmc x :optional
     .param pmc extra :slurpy
-    not_implemented()
+    .local pmc res
+    lua_checknumber(1, x)
+    res = x.'cbrt'()
+    .return (res)
 .end
 
 
-=item C<math.copysign ()>
-
-NOT YET IMPLEMENTED.
+=item C<math.copysign (x, y)>
 
 =cut
 
 .sub 'copysign'
+    .param pmc x :optional
+    .param pmc y :optional
     .param pmc extra :slurpy
-    not_implemented()
+    .local pmc res
+    lua_checknumber(1, x)
+    lua_checknumber(2, y)
+    res = x.'copysign'(y)
+    .return (res)
 .end
 
 
-=item C<math.erf ()>
-
-NOT YET IMPLEMENTED.
+=item C<math.erf (x)>
 
 =cut
 
 .sub 'erf'
+    .param pmc x :optional
     .param pmc extra :slurpy
-    not_implemented()
+    .local pmc res
+    lua_checknumber(1, x)
+    res = x.'erf'()
+    .return (res)
 .end
 
 
-=item C<math.erfc ()>
-
-NOT YET IMPLEMENTED.
+=item C<math.erfc (x)>
 
 =cut
 
 .sub 'erfc'
+    .param pmc x :optional
     .param pmc extra :slurpy
-    not_implemented()
+    .local pmc res
+    lua_checknumber(1, x)
+    res = x.'erfc'()
+    .return (res)
 .end
 
 
-=item C<math.exp2 ()>
-
-NOT YET IMPLEMENTED.
+=item C<math.exp2 (x)>
 
 =cut
 
 .sub 'exp2'
+    .param pmc x :optional
     .param pmc extra :slurpy
-    not_implemented()
+    .local pmc res
+    lua_checknumber(1, x)
+    res = x.'exp2'()
+    .return (res)
 .end
 
 
-=item C<math.expm1 ()>
-
-NOT YET IMPLEMENTED.
+=item C<math.expm1 (x)>
 
 =cut
 
 .sub 'expm1'
+    .param pmc x :optional
     .param pmc extra :slurpy
-    not_implemented()
+    .local pmc res
+    lua_checknumber(1, x)
+    res = x.'expm1'()
+    .return (res)
 .end
 
 
-=item C<math.fdim ()>
-
-NOT YET IMPLEMENTED.
+=item C<math.fdim (x, y)>
 
 =cut
 
 .sub 'fdim'
+    .param pmc x :optional
+    .param pmc y :optional
     .param pmc extra :slurpy
-    not_implemented()
+    .local pmc res
+    lua_checknumber(1, x)
+    lua_checknumber(2, y)
+    res = x.'fdim'(y)
+    .return (res)
 .end
 
 
-=item C<math.fma ()>
-
-NOT YET IMPLEMENTED.
+=item C<math.fma (x, y, z)>
 
 =cut
 
 .sub 'fma'
+    .param pmc x :optional
+    .param pmc y :optional
+    .param pmc z :optional
     .param pmc extra :slurpy
-    not_implemented()
+    .local pmc res
+    lua_checknumber(1, x)
+    lua_checknumber(2, y)
+    lua_checknumber(3, z)
+    res = x.'fma'(y, z)
+    .return (res)
 .end
 
 
-=item C<math.fmax ()>
-
-NOT YET IMPLEMENTED.
+=item C<math.fmax (x1, x2, ..., xn)>
 
 =cut
 
 .sub 'fmax'
-    .param pmc extra :slurpy
-    not_implemented()
+    .param pmc argv :slurpy
+    .local int argc
+    .local int i
+    .local pmc m, y
+    argc = argv
+    $P0 = argv[0]
+    i = 1
+    lua_checknumber(i, $P0)
+    m = clone $P0
+  L1:
+    if i >= argc goto L2
+    $P0 = argv[i]
+    inc i
+    lua_checknumber(i, $P0)
+    y = clone $P0
+    m = m.'fmax'(y)
+    goto L1
+  L2:
+    $P0 = clone m
+    .return ($P0)
 .end
 
 
 =item C<math.fmin ()>
 
-NOT YET IMPLEMENTED.
-
 =cut
 
 .sub 'fmin'
-    .param pmc extra :slurpy
-    not_implemented()
+    .param pmc argv :slurpy
+    .local int argc
+    .local int i
+    .local pmc m, y
+    argc = argv
+    $P0 = argv[0]
+    i = 1
+    lua_checknumber(i, $P0)
+    m = clone $P0
+  L1:
+    if i >= argc goto L2
+    $P0 = argv[i]
+    inc i
+    lua_checknumber(i, $P0)
+    y = clone $P0
+    m = m.'fmin'(y)
+    goto L1
+  L2:
+    $P0 = clone m
+    .return ($P0)
 .end
 
 
-=item C<math.fpclassify ()>
-
-NOT YET IMPLEMENTED.
+=item C<math.fpclassify (x)>
 
 =cut
 
 .sub 'fpclassify'
+    .param pmc x :optional
     .param pmc extra :slurpy
-    not_implemented()
+    .local pmc res
+    lua_checknumber(1, x)
+    res = x.'fpclassify'()
+    .return (res)
 .end
 
 
-=item C<math.gamma ()>
-
-NOT YET IMPLEMENTED.
+=item C<math.gamma (x)>
 
 =cut
 
 .sub 'gamma'
+    .param pmc x :optional
     .param pmc extra :slurpy
-    not_implemented()
+    .local pmc res
+    lua_checknumber(1, x)
+    res = x.'tgamma'()
+    .return (res)
 .end
 
 
-=item C<math.hypot ()>
-
-NOT YET IMPLEMENTED.
+=item C<math.hypot (x, y)>
 
 =cut
 
 .sub 'hypot'
+    .param pmc x :optional
+    .param pmc y :optional
     .param pmc extra :slurpy
-    not_implemented()
+    .local pmc res
+    lua_checknumber(1, x)
+    lua_checknumber(2, y)
+    res = x.'hypot'(y)
+    .return (res)
 .end
 
 
-=item C<math.ilogb ()>
-
-NOT YET IMPLEMENTED.
+=item C<math.ilogb (x)>
 
 =cut
 
 .sub 'ilogb'
+    .param pmc x :optional
     .param pmc extra :slurpy
-    not_implemented()
+    .local pmc res
+    lua_checknumber(1, x)
+    res = x.'ilogb'()
+    .return (res)
 .end
 
 
-=item C<math.isinf ()>
+=item C<math.isfinite (x)>
+
+=cut
+
+.sub 'isfinite'
+    .param pmc x :optional
+    .param pmc extra :slurpy
+    .local pmc res
+    lua_checknumber(1, x)
+    res = x.'isfinite'()
+    .return (res)
+.end
+
 
-NOT YET IMPLEMENTED.
+=item C<math.isinf (x)>
 
 =cut
 
 .sub 'isinf'
+    .param pmc x :optional
     .param pmc extra :slurpy
-    not_implemented()
+    .local pmc res
+    lua_checknumber(1, x)
+    res = x.'isinf'()
+    .return (res)
 .end
 
 
-=item C<math.isnan ()>
-
-NOT YET IMPLEMENTED.
+=item C<math.isnan (x)>
 
 =cut
 
 .sub 'isnan'
+    .param pmc x :optional
     .param pmc extra :slurpy
-    not_implemented()
+    .local pmc res
+    lua_checknumber(1, x)
+    res = x.'isnan'()
+    .return (res)
 .end
 
 
-=item C<math.isnormal ()>
-
-NOT YET IMPLEMENTED.
+=item C<math.isnormal (x)>
 
 =cut
 
 .sub 'isnormal'
+    .param pmc x :optional
     .param pmc extra :slurpy
-    not_implemented()
+    .local pmc res
+    lua_checknumber(1, x)
+    res = x.'isnormal'()
+    .return (res)
 .end
 
 
-=item C<math.lgamma ()>
-
-NOT YET IMPLEMENTED.
+=item C<math.lgamma (x)>
 
 =cut
 
 .sub 'lgamma'
+    .param pmc x :optional
     .param pmc extra :slurpy
-    not_implemented()
+    .local pmc res
+    lua_checknumber(1, x)
+    res = x.'lgamma'()
+    .return (res)
 .end
 
 
-=item C<math.log1p ()>
-
-NOT YET IMPLEMENTED.
+=item C<math.log1p (x)>
 
 =cut
 
 .sub 'log1p'
+    .param pmc x :optional
     .param pmc extra :slurpy
-    not_implemented()
+    .local pmc res
+    lua_checknumber(1, x)
+    res = x.'log1p'()
+    .return (res)
 .end
 
 
@@ -368,123 +465,151 @@
 .end
 
 
-=item C<math.logb ()>
-
-NOT YET IMPLEMENTED.
+=item C<math.logb (x)>
 
 =cut
 
 .sub 'logb'
+    .param pmc x :optional
     .param pmc extra :slurpy
-    not_implemented()
+    .local pmc res
+    lua_checknumber(1, x)
+    res = x.'logb'()
+    .return (res)
 .end
 
 
-=item C<math.nearbyint ()>
-
-NOT YET IMPLEMENTED.
+=item C<math.nearbyint (x)>
 
 =cut
 
 .sub 'nearbyint'
+    .param pmc x :optional
     .param pmc extra :slurpy
-    not_implemented()
+    .local pmc res
+    lua_checknumber(1, x)
+    res = x.'nearbyint'()
+    .return (res)
 .end
 
 
-=item C<math.nextafter ()>
-
-NOT YET IMPLEMENTED.
+=item C<math.nextafter (x, y)>
 
 =cut
 
 .sub 'nextafter'
+    .param pmc x :optional
+    .param pmc y :optional
     .param pmc extra :slurpy
-    not_implemented()
+    .local pmc res
+    lua_checknumber(1, x)
+    lua_checknumber(2, y)
+    res = x.'nextafter'(y)
+    .return (res)
 .end
 
 
-=item C<math.nexttoward ()>
-
-NOT YET IMPLEMENTED.
+=item C<math.nexttoward (x, y)>
 
 =cut
 
 .sub 'nexttoward'
+    .param pmc x :optional
+    .param pmc y :optional
     .param pmc extra :slurpy
-    not_implemented()
+    .local pmc res
+    lua_checknumber(1, x)
+    lua_checknumber(2, y)
+    res = x.'nexttoward'(y)
+    .return (res)
 .end
 
 
-=item C<math.remainder ()>
-
-NOT YET IMPLEMENTED.
+=item C<math.remainder (x, y)>
 
 =cut
 
 .sub 'remainder'
+    .param pmc x :optional
+    .param pmc y :optional
     .param pmc extra :slurpy
-    not_implemented()
+    .local pmc res
+    lua_checknumber(1, x)
+    lua_checknumber(2, y)
+    res = x.'remainder'(y)
+    .return (res)
 .end
 
 
-=item C<math.rint ()>
-
-NOT YET IMPLEMENTED.
+=item C<math.rint (x)>
 
 =cut
 
 .sub 'rint'
+    .param pmc x :optional
     .param pmc extra :slurpy
-    not_implemented()
+    .local pmc res
+    lua_checknumber(1, x)
+    res = x.'rint'()
+    .return (res)
 .end
 
 
-=item C<math.round ()>
-
-NOT YET IMPLEMENTED.
+=item C<math.round (x)>
 
 =cut
 
 .sub 'round'
+    .param pmc x :optional
     .param pmc extra :slurpy
-    not_implemented()
+    .local pmc res
+    lua_checknumber(1, x)
+    res = x.'round'()
+    .return (res)
 .end
 
 
-=item C<math.scalbn ()>
-
-NOT YET IMPLEMENTED.
+=item C<math.scalbn (x, ex)>
 
 =cut
 
 .sub 'scalbn'
+    .param pmc x :optional
+    .param pmc ex :optional
     .param pmc extra :slurpy
-    not_implemented()
+    .local pmc res
+    lua_checknumber(1, x)
+    lua_checknumber(2, ex)
+    res = x.'scalbn'(ex)
+    .return (res)
 .end
 
 
-=item C<math.signbit ()>
-
-NOT YET IMPLEMENTED.
+=item C<math.signbit (x)>
 
 =cut
 
 .sub 'signbit'
+    .param pmc x :optional
     .param pmc extra :slurpy
-    not_implemented()
+    .local pmc res
+    lua_checknumber(1, x)
+    res = x.'signbit'()
+    .return (res)
 .end
 
 
-=item C<math.trunc ()>
-
-NOT YET IMPLEMENTED.
+=item C<math.trunc (x)>
 
 =cut
 
 .sub 'trunc'
+    .param pmc x :optional
     .param pmc extra :slurpy
-    not_implemented()
+    .local pmc res
+    lua_checknumber(1, x)
+    res = x.'trunc'()
+    .return (res)
 .end
 
 

Modified: trunk/languages/lua/src/pmc/luanumber.pmc
==============================================================================
--- trunk/languages/lua/src/pmc/luanumber.pmc	(original)
+++ trunk/languages/lua/src/pmc/luanumber.pmc	Tue Dec  2 09:15:37 2008
@@ -873,6 +873,217 @@
 
 =over 4
 
+=item C<PMC* acosh()>
+
+=cut
+
+*/
+    METHOD PMC* acosh() {
+        PMC *retval = pmc_new(INTERP, dynpmc_LuaNumber);
+        VTABLE_set_number_native(INTERP, retval,
+                                 acosh(VTABLE_get_number(INTERP, SELF)));
+        RETURN(PMC *retval);
+    }
+
+/*
+
+=item C<PMC* asinh()>
+
+=cut
+
+*/
+    METHOD PMC* asinh() {
+        PMC *retval = pmc_new(INTERP, dynpmc_LuaNumber);
+        VTABLE_set_number_native(INTERP, retval,
+                                 asinh(VTABLE_get_number(INTERP, SELF)));
+        RETURN(PMC *retval);
+    }
+
+/*
+
+=item C<PMC* atanh()>
+
+=cut
+
+*/
+    METHOD PMC* atanh() {
+        PMC *retval = pmc_new(INTERP, dynpmc_LuaNumber);
+        VTABLE_set_number_native(INTERP, retval,
+                                 atanh(VTABLE_get_number(INTERP, SELF)));
+        RETURN(PMC *retval);
+    }
+
+/*
+
+=item C<PMC* cbrt()>
+
+=cut
+
+*/
+    METHOD PMC* cbrt() {
+        PMC *retval = pmc_new(INTERP, dynpmc_LuaNumber);
+        VTABLE_set_number_native(INTERP, retval,
+                                 cbrt(VTABLE_get_number(INTERP, SELF)));
+        RETURN(PMC *retval);
+    }
+
+/*
+
+=item C<PMC* copysign(PMC* y)>
+
+=cut
+
+*/
+    METHOD PMC* copysign(PMC* y) {
+        PMC *retval = pmc_new(INTERP, dynpmc_LuaNumber);
+        VTABLE_set_number_native(INTERP, retval,
+                                 copysign(VTABLE_get_number(INTERP, SELF),
+                                          VTABLE_get_number(INTERP, y)));
+        RETURN(PMC *retval);
+    }
+
+/*
+
+=item C<PMC* erf()>
+
+=cut
+
+*/
+    METHOD PMC* erf() {
+        PMC *retval = pmc_new(INTERP, dynpmc_LuaNumber);
+        VTABLE_set_number_native(INTERP, retval,
+                                 erf(VTABLE_get_number(INTERP, SELF)));
+        RETURN(PMC *retval);
+    }
+
+/*
+
+=item C<PMC* erfc()>
+
+=cut
+
+*/
+    METHOD PMC* erfc() {
+        PMC *retval = pmc_new(INTERP, dynpmc_LuaNumber);
+        VTABLE_set_number_native(INTERP, retval,
+                                 erfc(VTABLE_get_number(INTERP, SELF)));
+        RETURN(PMC *retval);
+    }
+
+/*
+
+=item C<PMC* exp2()>
+
+=cut
+
+*/
+    METHOD PMC* exp2() {
+        PMC *retval = pmc_new(INTERP, dynpmc_LuaNumber);
+        VTABLE_set_number_native(INTERP, retval,
+                                 exp2(VTABLE_get_number(INTERP, SELF)));
+        RETURN(PMC *retval);
+    }
+
+/*
+
+=item C<PMC* expm1()>
+
+=cut
+
+*/
+    METHOD PMC* expm1() {
+        PMC *retval = pmc_new(INTERP, dynpmc_LuaNumber);
+        VTABLE_set_number_native(INTERP, retval,
+                                 expm1(VTABLE_get_number(INTERP, SELF)));
+        RETURN(PMC *retval);
+    }
+
+/*
+
+=item C<PMC* fdim(PMC* y)>
+
+=cut
+
+*/
+    METHOD PMC* fdim(PMC* y) {
+        PMC *retval = pmc_new(INTERP, dynpmc_LuaNumber);
+        VTABLE_set_number_native(INTERP, retval,
+                                 fdim(VTABLE_get_number(INTERP, SELF),
+                                      VTABLE_get_number(INTERP, y)));
+        RETURN(PMC *retval);
+    }
+
+/*
+
+=item C<PMC* fma(PMC* y, PMC* z)>
+
+=cut
+
+*/
+    METHOD PMC* fma(PMC* y, PMC* z) {
+        PMC *retval = pmc_new(INTERP, dynpmc_LuaNumber);
+        VTABLE_set_number_native(INTERP, retval,
+                                 fma(VTABLE_get_number(INTERP, SELF),
+                                     VTABLE_get_number(INTERP, y),
+                                     VTABLE_get_number(INTERP, z)));
+        RETURN(PMC *retval);
+    }
+
+/*
+
+=item C<PMC* fmax(PMC* y)>
+
+=cut
+
+*/
+    METHOD PMC* fmax(PMC* y) {
+        PMC *retval = pmc_new(INTERP, dynpmc_LuaNumber);
+        VTABLE_set_number_native(INTERP, retval,
+                                 fmax(VTABLE_get_number(INTERP, SELF),
+                                      VTABLE_get_number(INTERP, y)));
+        RETURN(PMC *retval);
+    }
+
+/*
+
+=item C<PMC* fmin(PMC* y)>
+
+=cut
+
+*/
+    METHOD PMC* fmin(PMC* y) {
+        PMC *retval = pmc_new(INTERP, dynpmc_LuaNumber);
+        VTABLE_set_number_native(INTERP, retval,
+                                 fmin(VTABLE_get_number(INTERP, SELF),
+                                      VTABLE_get_number(INTERP, y)));
+        RETURN(PMC *retval);
+    }
+
+/*
+
+=item C<PMC* fpclassify()>
+
+=cut
+
+*/
+    METHOD PMC* fpclassify() {
+        PMC *retval = pmc_new(INTERP, dynpmc_LuaString);
+        const char *p;
+        switch (fpclassify(VTABLE_get_number(INTERP, SELF))) {
+        case FP_INFINITE:       p = "inf";              break;
+        case FP_NAN:            p = "nan";              break;
+        case FP_NORMAL:         p = "normal";           break;
+        case FP_SUBNORMAL:      p = "subnormal";        break;
+        case FP_ZERO:           p = "zero";             break;
+        default:                p = "bad fpclassify";
+        }
+        VTABLE_set_string_native(INTERP, retval,
+                                 const_string(INTERP, p));
+        RETURN(PMC *retval);
+    }
+
+/*
+
 =item C<PMC* frexp()>
 
 =cut
@@ -896,6 +1107,91 @@
 
 /*
 
+=item C<PMC* hypot(PMC* y)>
+
+=cut
+
+*/
+    METHOD PMC* hypot(PMC* y) {
+        PMC *retval = pmc_new(INTERP, dynpmc_LuaNumber);
+        VTABLE_set_number_native(INTERP, retval,
+                                 hypot(VTABLE_get_number(INTERP, SELF),
+                                       VTABLE_get_number(INTERP, y)));
+        RETURN(PMC *retval);
+    }
+
+/*
+
+=item C<PMC* ilogb()>
+
+=cut
+
+*/
+    METHOD PMC* ilogb() {
+        PMC *retval = pmc_new(INTERP, dynpmc_LuaNumber);
+        VTABLE_set_number_native(INTERP, retval,
+                                 ilogb(VTABLE_get_number(INTERP, SELF)));
+        RETURN(PMC *retval);
+    }
+
+/*
+
+=item C<PMC* isfinite()>
+
+=cut
+
+*/
+    METHOD PMC* isfinite() {
+        PMC *retval = pmc_new(INTERP, dynpmc_LuaBoolean);
+        VTABLE_set_bool(INTERP, retval,
+                        isfinite(VTABLE_get_number(INTERP, SELF)));
+        RETURN(PMC *retval);
+    }
+
+/*
+
+=item C<PMC* isinf()>
+
+=cut
+
+*/
+    METHOD PMC* isinf() {
+        PMC *retval = pmc_new(INTERP, dynpmc_LuaBoolean);
+        VTABLE_set_bool(INTERP, retval,
+                        isinf(VTABLE_get_number(INTERP, SELF)));
+        RETURN(PMC *retval);
+    }
+
+/*
+
+=item C<PMC* isnan()>
+
+=cut
+
+*/
+    METHOD PMC* isnan() {
+        PMC *retval = pmc_new(INTERP, dynpmc_LuaBoolean);
+        VTABLE_set_bool(INTERP, retval,
+                        isnan(VTABLE_get_number(INTERP, SELF)));
+        RETURN(PMC *retval);
+    }
+
+/*
+
+=item C<PMC* isnormal()>
+
+=cut
+
+*/
+    METHOD PMC* isnormal() {
+        PMC *retval = pmc_new(INTERP, dynpmc_LuaBoolean);
+        VTABLE_set_bool(INTERP, retval,
+                        isnormal(VTABLE_get_number(INTERP, SELF)));
+        RETURN(PMC *retval);
+    }
+
+/*
+
 =item C<PMC* ldexp(PMC *x, PMC *expn)>
 
 =cut
@@ -912,6 +1208,62 @@
 
 /*
 
+=item C<PMC* lgamma()>
+
+=cut
+
+*/
+    METHOD PMC* lgamma() {
+        PMC *retval = pmc_new(INTERP, dynpmc_LuaNumber);
+        VTABLE_set_number_native(INTERP, retval,
+                                 lgamma(VTABLE_get_number(INTERP, SELF)));
+        RETURN(PMC *retval);
+    }
+
+/*
+
+=item C<PMC* log1p()>
+
+=cut
+
+*/
+    METHOD PMC* log1p() {
+        PMC *retval = pmc_new(INTERP, dynpmc_LuaNumber);
+        VTABLE_set_number_native(INTERP, retval,
+                                 log1p(VTABLE_get_number(INTERP, SELF)));
+        RETURN(PMC *retval);
+    }
+
+/*
+
+=item C<PMC* log2()>
+
+=cut
+
+*/
+    METHOD PMC* log2() {
+        PMC *retval = pmc_new(INTERP, dynpmc_LuaNumber);
+        VTABLE_set_number_native(INTERP, retval,
+                                 log2(VTABLE_get_number(INTERP, SELF)));
+        RETURN(PMC *retval);
+    }
+
+/*
+
+=item C<PMC* logb()>
+
+=cut
+
+*/
+    METHOD PMC* logb() {
+        PMC *retval = pmc_new(INTERP, dynpmc_LuaNumber);
+        VTABLE_set_number_native(INTERP, retval,
+                                 logb(VTABLE_get_number(INTERP, SELF)));
+        RETURN(PMC *retval);
+    }
+
+/*
+
 =item C<PMC* modf()>
 
 =cut
@@ -935,6 +1287,50 @@
 
 /*
 
+=item C<PMC* nearbyint()>
+
+=cut
+
+*/
+    METHOD PMC* nearbyint() {
+        PMC *retval = pmc_new(INTERP, dynpmc_LuaNumber);
+        VTABLE_set_number_native(INTERP, retval,
+                                 nearbyint(VTABLE_get_number(INTERP, SELF)));
+        RETURN(PMC *retval);
+    }
+
+/*
+
+=item C<PMC* nextafter(PMC* y)>
+
+=cut
+
+*/
+    METHOD PMC* nextafter(PMC* y) {
+        PMC *retval = pmc_new(INTERP, dynpmc_LuaNumber);
+        VTABLE_set_number_native(INTERP, retval,
+                                 nextafter(VTABLE_get_number(INTERP, SELF),
+                                           VTABLE_get_number(INTERP, y)));
+        RETURN(PMC *retval);
+    }
+
+/*
+
+=item C<PMC* nexttoward(PMC* y)>
+
+=cut
+
+*/
+    METHOD PMC* nexttoward(PMC* y) {
+        PMC *retval = pmc_new(INTERP, dynpmc_LuaNumber);
+        VTABLE_set_number_native(INTERP, retval,
+                                 nexttoward(VTABLE_get_number(INTERP, SELF),
+                                            VTABLE_get_number(INTERP, y)));
+        RETURN(PMC *retval);
+    }
+
+/*
+
 =item C<PMC *rawequal(PMC *value)>
 
 =cut
@@ -954,6 +1350,106 @@
 
 /*
 
+=item C<PMC* remainder(PMC* y)>
+
+=cut
+
+*/
+    METHOD PMC* remainder(PMC* y) {
+        PMC *retval = pmc_new(INTERP, dynpmc_LuaNumber);
+        VTABLE_set_number_native(INTERP, retval,
+                                 remainder(VTABLE_get_number(INTERP, SELF),
+                                           VTABLE_get_number(INTERP, y)));
+        RETURN(PMC *retval);
+    }
+
+/*
+
+=item C<PMC* rint()>
+
+=cut
+
+*/
+    METHOD PMC* rint() {
+        PMC *retval = pmc_new(INTERP, dynpmc_LuaNumber);
+        VTABLE_set_number_native(INTERP, retval,
+                                 rint(VTABLE_get_number(INTERP, SELF)));
+        RETURN(PMC *retval);
+    }
+
+/*
+
+=item C<PMC* round()>
+
+=cut
+
+*/
+    METHOD PMC* round() {
+        PMC *retval = pmc_new(INTERP, dynpmc_LuaNumber);
+        VTABLE_set_number_native(INTERP, retval,
+                                 round(VTABLE_get_number(INTERP, SELF)));
+        RETURN(PMC *retval);
+    }
+
+/*
+
+=item C<PMC* scalbn(PMC* ex)>
+
+=cut
+
+*/
+    METHOD PMC* scalbn(PMC* ex) {
+        PMC *retval = pmc_new(INTERP, dynpmc_LuaNumber);
+        VTABLE_set_number_native(INTERP, retval,
+                                 scalbn(VTABLE_get_number(INTERP, SELF),
+                                        VTABLE_get_number(INTERP, ex)));
+        RETURN(PMC *retval);
+    }
+
+/*
+
+=item C<PMC* signbit()>
+
+=cut
+
+*/
+    METHOD PMC* signbit() {
+        PMC *retval = pmc_new(INTERP, dynpmc_LuaNumber);
+        VTABLE_set_number_native(INTERP, retval,
+                                 signbit(VTABLE_get_number(INTERP, SELF)));
+        RETURN(PMC *retval);
+    }
+
+/*
+
+=item C<PMC* tgamma()>
+
+=cut
+
+*/
+    METHOD PMC* tgamma() {
+        PMC *retval = pmc_new(INTERP, dynpmc_LuaNumber);
+        VTABLE_set_number_native(INTERP, retval,
+                                 tgamma(VTABLE_get_number(INTERP, SELF)));
+        RETURN(PMC *retval);
+    }
+
+/*
+
+=item C<PMC* trunc()>
+
+=cut
+
+*/
+    METHOD PMC* trunc() {
+        PMC *retval = pmc_new(INTERP, dynpmc_LuaNumber);
+        VTABLE_set_number_native(INTERP, retval,
+                                 trunc(VTABLE_get_number(INTERP, SELF)));
+        RETURN(PMC *retval);
+    }
+
+/*
+
 =item C<PMC *tonumber()>
 
 =cut

Modified: trunk/languages/lua/t/mathx.t
==============================================================================
--- trunk/languages/lua/t/mathx.t	(original)
+++ trunk/languages/lua/t/mathx.t	Tue Dec  2 09:15:37 2008
@@ -22,7 +22,7 @@
 use FindBin;
 use lib "$FindBin::Bin";
 
-use Parrot::Test tests => 4;
+use Parrot::Test tests => 23;
 use Parrot::Config;
 use Test::More;
 use Parrot::Test::Lua;
@@ -57,6 +57,132 @@
 OUTPUT
 }
 
+language_output_like( 'lua', << 'CODE', << 'OUTPUT', 'function acosh' );
+require 'mathx'
+print(math.acosh(2))
+CODE
+/^1\.316/
+OUTPUT
+
+language_output_like( 'lua', << 'CODE', << 'OUTPUT', 'function asinh' );
+require 'mathx'
+print(math.asinh(0.5))
+CODE
+/^0\.481/
+OUTPUT
+
+language_output_like( 'lua', << 'CODE', << 'OUTPUT', 'function atanh' );
+require 'mathx'
+print(math.atanh(0.5))
+CODE
+/^0\.549/
+OUTPUT
+
+language_output_like( 'lua', << 'CODE', << 'OUTPUT', 'function cbrt' );
+require 'mathx'
+print(math.cbrt(2))
+CODE
+/^1\.259/
+OUTPUT
+
+language_output_like( 'lua', << 'CODE', << 'OUTPUT', 'function erf' );
+require 'mathx'
+print(math.erf(2))
+CODE
+/^0\.995/
+OUTPUT
+
+language_output_like( 'lua', << 'CODE', << 'OUTPUT', 'function erfc' );
+require 'mathx'
+print(math.erfc(2))
+CODE
+/^0\.004/
+OUTPUT
+
+language_output_like( 'lua', << 'CODE', << 'OUTPUT', 'function exp2' );
+require 'mathx'
+print(math.exp2(3))
+CODE
+/^8$/
+OUTPUT
+
+language_output_like( 'lua', << 'CODE', << 'OUTPUT', 'function expm1' );
+require 'mathx'
+print(math.expm1(2))
+CODE
+/^6\.389/
+OUTPUT
+
+language_output_is( 'lua', << 'CODE', << 'OUTPUT', 'function fpclassify' );
+require 'mathx'
+print(math.fpclassify(1))
+CODE
+normal
+OUTPUT
+
+language_output_like( 'lua', << 'CODE', << 'OUTPUT', 'function gamma' );
+require 'mathx'
+print(math.gamma(0.5))
+CODE
+/^1\.772/
+OUTPUT
+
+language_output_like( 'lua', << 'CODE', << 'OUTPUT', 'function hypot' );
+require 'mathx'
+print(math.hypot(2, 3))
+CODE
+/^3\.605/
+OUTPUT
+
+language_output_like( 'lua', << 'CODE', << 'OUTPUT', 'function ilogb' );
+require 'mathx'
+print(math.ilogb(47))
+CODE
+/^5$/
+OUTPUT
+
+language_output_is( 'lua', << 'CODE', << 'OUTPUT', 'function isfinite' );
+require 'mathx'
+print(math.isfinite(1))
+CODE
+true
+OUTPUT
+
+language_output_is( 'lua', << 'CODE', << 'OUTPUT', 'function isinf' );
+require 'mathx'
+print(math.isinf(1))
+CODE
+false
+OUTPUT
+
+language_output_is( 'lua', << 'CODE', << 'OUTPUT', 'function isnan' );
+require 'mathx'
+print(math.isnan(1))
+CODE
+false
+OUTPUT
+
+language_output_is( 'lua', << 'CODE', << 'OUTPUT', 'function isnormal' );
+require 'mathx'
+print(math.isnormal(1))
+CODE
+true
+OUTPUT
+
+language_output_like( 'lua', << 'CODE', << 'OUTPUT', 'function lgamma' );
+require 'mathx'
+print(math.lgamma(0.5))
+CODE
+/^0\.572/
+OUTPUT
+
+language_output_like( 'lua', << 'CODE', << 'OUTPUT', 'function log1p' );
+require 'mathx'
+print(math.log1p(47))
+CODE
+/^3\.871/
+OUTPUT
+
 language_output_like( 'lua', << 'CODE', << 'OUTPUT', 'function log2' );
 require 'mathx'
 print(math.log2(47))
@@ -64,6 +190,13 @@
 /^5\.554/
 OUTPUT
 
+language_output_like( 'lua', << 'CODE', << 'OUTPUT', 'function logb' );
+require 'mathx'
+print(math.logb(47))
+CODE
+/^5$/
+OUTPUT
+
 
 # Local Variables:
 #   mode: cperl



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About