[svn:parrot] r48564 - in trunk: src/dynoplibs src/ops src/pmc t/dynoplibs t/pmc

cotto at svn.parrot.org cotto at svn.parrot.org
Thu Aug 19 02:03:12 UTC 2010


Author: cotto
Date: Thu Aug 19 02:03:11 2010
New Revision: 48564
URL: https://trac.parrot.org/parrot/changeset/48564

Log:
[pmc] add cot and csc to the Float PMC, closing TT #481
patch courtesy of paul_the_greek++

Modified:
   trunk/src/dynoplibs/trans.ops
   trunk/src/ops/set.ops
   trunk/src/pmc/float.pmc
   trunk/t/dynoplibs/trans-infnan.t
   trunk/t/dynoplibs/trans.t
   trunk/t/pmc/float.t

Modified: trunk/src/dynoplibs/trans.ops
==============================================================================
--- trunk/src/dynoplibs/trans.ops	Wed Aug 18 13:36:35 2010	(r48563)
+++ trunk/src/dynoplibs/trans.ops	Thu Aug 19 02:03:11 2010	(r48564)
@@ -105,6 +105,30 @@
 
 ########################################
 
+=item B<cot>(out NUM, in NUM)
+
+Set $1 to the cotangent of $2 (given in radians).
+
+=cut
+
+inline op cot(out NUM, in NUM) :base_math {
+    $1 = ((FLOATVAL)1) / tan((FLOATVAL)$2);
+}
+
+########################################
+
+=item B<csc>(out NUM, in NUM)
+
+Set $1 to the cosecant of $2 (given in radians).
+
+=cut
+
+inline op csc(out NUM, in NUM) :base_math {
+    $1 = ((FLOATVAL)1) / sin((FLOATVAL)$2);
+}
+
+########################################
+
 =item B<exp>(out NUM, in NUM)
 
 Set $1 to I<e> raised to the power $2. I<e> is the base of the natural

Modified: trunk/src/ops/set.ops
==============================================================================
--- trunk/src/ops/set.ops	Wed Aug 18 13:36:35 2010	(r48563)
+++ trunk/src/ops/set.ops	Thu Aug 19 02:03:11 2010	(r48564)
@@ -40,6 +40,9 @@
 
 =item B<set>(out INT, in NUM)
 
+A floating-point number is truncated (rounded toward zero) when assigned
+to an integer register.
+
 =item B<set>(out INT, invar PMC)
 
 =item B<set>(out INT, invar PMC)

Modified: trunk/src/pmc/float.pmc
==============================================================================
--- trunk/src/pmc/float.pmc	Wed Aug 18 13:36:35 2010	(r48563)
+++ trunk/src/pmc/float.pmc	Thu Aug 19 02:03:11 2010	(r48564)
@@ -77,7 +77,8 @@
 
 =item C<INTVAL get_integer()>
 
-Returns an integer representation of the number (by casting).
+Returns an integer representation of the number by truncating
+(rounding toward zero).
 
 =cut
 
@@ -391,6 +392,10 @@
 
 =item C<METHOD PMC *cosh()>
 
+=item C<METHOD PMC *cot()>
+
+=item C<METHOD PMC *csc()>
+
 =item C<METHOD PMC *exp()>
 
 =item C<METHOD PMC *ln()>
@@ -425,13 +430,6 @@
         RETURN(PMC *d);
     }
 
-    METHOD cos() {
-        PMC * const d  = Parrot_pmc_new(INTERP,
-                Parrot_get_ctx_HLL_type(INTERP, enum_class_Float));
-        SET_ATTR_fv(INTERP, d, cos(SELF.get_number()));
-        RETURN(PMC *d);
-    }
-
     METHOD asec() {
         PMC * const d  = Parrot_pmc_new(INTERP, VTABLE_type(INTERP, SELF));
         SET_ATTR_fv(INTERP, d, acos(1.0 / SELF.get_number()));
@@ -456,12 +454,31 @@
         RETURN(PMC *d);
     }
 
+    METHOD cos() {
+        PMC * const d  = Parrot_pmc_new(INTERP,
+                Parrot_get_ctx_HLL_type(INTERP, enum_class_Float));
+        SET_ATTR_fv(INTERP, d, cos(SELF.get_number()));
+        RETURN(PMC *d);
+    }
+
     METHOD cosh() {
         PMC * const d  = Parrot_pmc_new(INTERP, VTABLE_type(INTERP, SELF));
         SET_ATTR_fv(INTERP, d, cosh(SELF.get_number()));
         RETURN(PMC *d);
     }
 
+    METHOD cot() {
+        PMC * const d  = Parrot_pmc_new(INTERP, VTABLE_type(INTERP, SELF));
+        SET_ATTR_fv(INTERP, d, 1.0 / tan(SELF.get_number()));
+        RETURN(PMC *d);
+    }
+
+    METHOD csc() {
+        PMC * const d  = Parrot_pmc_new(INTERP, VTABLE_type(INTERP, SELF));
+        SET_ATTR_fv(INTERP, d, 1.0 / sin(SELF.get_number()));
+        RETURN(PMC *d);
+    }
+
     METHOD exp() {
         PMC * const d  = Parrot_pmc_new(INTERP, VTABLE_type(INTERP, SELF));
         SET_ATTR_fv(INTERP, d, exp(SELF.get_number()));

Modified: trunk/t/dynoplibs/trans-infnan.t
==============================================================================
--- trunk/t/dynoplibs/trans-infnan.t	Wed Aug 18 13:36:35 2010	(r48563)
+++ trunk/t/dynoplibs/trans-infnan.t	Thu Aug 19 02:03:11 2010	(r48564)
@@ -20,7 +20,7 @@
 
 .sub main :main
     .include 'test_more.pir'
-    plan(67)
+    plan(70)
 
     test_exp()
     test_sin()
@@ -36,6 +36,7 @@
     test_coth()
     test_acot()
     test_sec()
+    test_csc()
     test_sech()
     test_asec()
     test_ln()
@@ -232,6 +233,18 @@
     is($N1, 'NaN', '... sec NaN')
 .end
 
+.sub test_csc
+    $N0 = 'Inf'
+    $N1 = csc $N0
+    is($N1, 'NaN', 'csc: csc Inf')
+    $N0 = '-Inf'
+    $N1 = csc $N0
+    is($N1, 'NaN', '... csc -Inf')
+    $N0 = 'NaN'
+    $N1 = csc $N0
+    is($N1, 'NaN', '... csc NaN')
+.end
+
 .sub test_sech
     $N0 = 'Inf'
     $N1 = sech $N0
@@ -295,20 +308,16 @@
     is($N1, 'NaN', '... log2 -Inf')
 .end
 
-
 .sub test_cot
     $N0 = 'Inf'
-    #$N1 = cot $N0
-    #is($N1, 'NaN', 'cot: cot Inf')
-    todo(0, 'cot Inf', 'cot/coth/acot not implemented for real numbers')
-    $N0 = '-Inf'
-    #$N1 = cot $N0
-    #is($N1, 'NaN', '... cot -Inf')
-    todo(0, 'cot -Inf', 'cot/coth/acot not implemented for real numbers')
-    $N0 = 'NaN'
-    #$N1 = cot $N0
-    #is($N1, 'NaN', '... cot NaN')
-    todo(0, 'cot NaN', 'cot/coth/acot not implemented for real numbers')
+    $N1 = cot $N0
+    is($N1, 'NaN', 'cot: cot Inf')
+    $N0 = '-Inf'
+    $N1 = cot $N0
+    is($N1, 'NaN', '... cot -Inf')
+    $N0 = 'NaN'
+    $N1 = cot $N0
+    is($N1, 'NaN', '... cot NaN')
 .end
 
 .sub test_pow

Modified: trunk/t/dynoplibs/trans.t
==============================================================================
--- trunk/t/dynoplibs/trans.t	Wed Aug 18 13:36:35 2010	(r48563)
+++ trunk/t/dynoplibs/trans.t	Thu Aug 19 02:03:11 2010	(r48564)
@@ -23,7 +23,7 @@
     .local num epsilon
     epsilon = _epsilon()
 
-    plan(69)
+    plan(77)
 
     test_sin_n(epsilon)
     test_sin_i(epsilon)
@@ -31,8 +31,12 @@
     test_cos_i(epsilon)
     test_tan_n(epsilon)
     test_tan_i(epsilon)
+    test_cot_n(epsilon)
+    test_cot_i(epsilon)
     test_sec_n(epsilon)
     test_sec_i(epsilon)
+    test_csc_n(epsilon)
+    test_csc_i(epsilon)
     test_atan_n(epsilon)
     test_atan_i(epsilon)
     test_asin_n(epsilon)
@@ -137,6 +141,26 @@
     is($N0, 1.557408, "tan(1)", epsilon)
 .end
 
+.sub test_cot_n
+    .param num epsilon
+
+    $N0 = cot 0.5
+    is($N0,  1.8305, "cot(0.5)", epsilon)
+
+    $N0 = cot 1.0
+    is($N0,  0.64209, "cot(1.0)", epsilon)
+.end
+
+.sub test_cot_i
+    .param num epsilon
+
+    $N0 = cot 1
+    is($N0, 0.64209, "cot(1)", epsilon)
+
+    $N0 = cot 2
+    is($N0,  -0.45766, "cot(2)", epsilon)
+.end
+
 .sub test_sec_n
     .param num epsilon
 
@@ -153,6 +177,26 @@
     is($N1, 1.850816, "sec(1)", epsilon)
 .end
 
+.sub test_csc_n
+    .param num epsilon
+
+    $N0 = csc 0.5
+    is($N0,   2.0858, "csc(0.5)", epsilon)
+
+    $N0 = csc 1.0
+    is($N0,  1.1884, "csc(1.0)", epsilon)
+.end
+
+.sub test_csc_i
+    .param num epsilon
+
+    $N0 = csc 1
+    is($N0, 1.1884, "csc(1)", epsilon)
+
+    $N0 = csc 2
+    is($N0,   1.0998, "csc(2)", epsilon)
+.end
+
 .sub test_atan_n
     .param num epsilon
 

Modified: trunk/t/pmc/float.t
==============================================================================
--- trunk/t/pmc/float.t	Wed Aug 18 13:36:35 2010	(r48563)
+++ trunk/t/pmc/float.t	Thu Aug 19 02:03:11 2010	(r48564)
@@ -16,7 +16,7 @@
 
 =cut
 
-.const int TESTS = 162
+.const int TESTS = 166
 .const num PRECISION = 0.000001
 
 .sub 'test' :main
@@ -78,10 +78,12 @@
     log10_method()
     log2_method()
     sec_method()
+    csc_method()
     sech_method()
     sin_method()
     sinh_method()
     tan_method()
+    cot_method()
     tanh_method()
     sqrt_method()
 .end
@@ -998,6 +1000,11 @@
     test_method('sec', 0.5, 1.139493927)
 .end
 
+.sub 'csc_method'
+    test_method('csc', 0.5, 2.0858296)
+    test_method('csc', 1.0, 1.1883951)
+.end
+
 .sub 'sech_method'
     test_method('sech', 0.0, 1.0)
     test_method('sech', 0.5, 0.886818884)
@@ -1018,6 +1025,11 @@
     test_method('tan', 0.5, 0.546302490)
 .end
 
+.sub 'cot_method'
+    test_method('cot', 0.5, 1.8304877)
+    test_method('cot', 1.0, 0.64209262)
+.end
+
 .sub 'tanh_method'
     test_method('tanh', 0.0, 0.0)
     test_method('tanh', 0.5, 0.462117157)


More information about the parrot-commits mailing list