Ticket #481: PCA-patch-003.patch

File PCA-patch-003.patch, 7.5 KB (added by Paul C. Anagnostopoulos, 11 years ago)
  • src/ops/set.ops

     
    4040 
    4141=item B<set>(out INT, in NUM) 
    4242 
     43A floating-point number is truncated (rounded toward zero) when assigned 
     44to an integer register. 
     45 
    4346=item B<set>(out INT, invar PMC) 
    4447 
    4548=item B<set>(out INT, invar PMC) 
  • src/dynoplibs/trans.ops

     
    105105 
    106106######################################## 
    107107 
     108=item B<cot>(out NUM, in NUM) 
     109 
     110Set $1 to the cotangent of $2 (given in radians). 
     111 
     112=cut 
     113 
     114inline op cot(out NUM, in NUM) :base_math { 
     115    $1 = ((FLOATVAL)1) / tan((FLOATVAL)$2); 
     116} 
     117 
     118######################################## 
     119 
     120=item B<csc>(out NUM, in NUM) 
     121 
     122Set $1 to the cosecant of $2 (given in radians). 
     123 
     124=cut 
     125 
     126inline op csc(out NUM, in NUM) :base_math { 
     127    $1 = ((FLOATVAL)1) / sin((FLOATVAL)$2); 
     128} 
     129 
     130######################################## 
     131 
    108132=item B<exp>(out NUM, in NUM) 
    109133 
    110134Set $1 to I<e> raised to the power $2. I<e> is the base of the natural 
  • src/pmc/float.pmc

     
    7777 
    7878=item C<INTVAL get_integer()> 
    7979 
    80 Returns an integer representation of the number (by casting). 
     80Returns an integer representation of the number by truncating 
     81(rounding toward zero). 
    8182 
    8283=cut 
    8384 
     
    391392 
    392393=item C<METHOD PMC *cosh()> 
    393394 
     395=item C<METHOD PMC *cot()> 
     396 
     397=item C<METHOD PMC *csc()> 
     398 
    394399=item C<METHOD PMC *exp()> 
    395400 
    396401=item C<METHOD PMC *ln()> 
     
    425430        RETURN(PMC *d); 
    426431    } 
    427432 
    428     METHOD cos() { 
    429         PMC * const d  = Parrot_pmc_new(INTERP, 
    430                 Parrot_get_ctx_HLL_type(INTERP, enum_class_Float)); 
    431         SET_ATTR_fv(INTERP, d, cos(SELF.get_number())); 
    432         RETURN(PMC *d); 
    433     } 
    434  
    435433    METHOD asec() { 
    436434        PMC * const d  = Parrot_pmc_new(INTERP, VTABLE_type(INTERP, SELF)); 
    437435        SET_ATTR_fv(INTERP, d, acos(1.0 / SELF.get_number())); 
     
    456454        RETURN(PMC *d); 
    457455    } 
    458456 
     457    METHOD cos() { 
     458        PMC * const d  = Parrot_pmc_new(INTERP, 
     459                Parrot_get_ctx_HLL_type(INTERP, enum_class_Float)); 
     460        SET_ATTR_fv(INTERP, d, cos(SELF.get_number())); 
     461        RETURN(PMC *d); 
     462    } 
     463 
    459464    METHOD cosh() { 
    460465        PMC * const d  = Parrot_pmc_new(INTERP, VTABLE_type(INTERP, SELF)); 
    461466        SET_ATTR_fv(INTERP, d, cosh(SELF.get_number())); 
    462467        RETURN(PMC *d); 
    463468    } 
    464469 
     470    METHOD cot() { 
     471        PMC * const d  = Parrot_pmc_new(INTERP, VTABLE_type(INTERP, SELF)); 
     472        SET_ATTR_fv(INTERP, d, 1.0 / tan(SELF.get_number())); 
     473        RETURN(PMC *d); 
     474    } 
     475 
     476    METHOD csc() { 
     477        PMC * const d  = Parrot_pmc_new(INTERP, VTABLE_type(INTERP, SELF)); 
     478        SET_ATTR_fv(INTERP, d, 1.0 / sin(SELF.get_number())); 
     479        RETURN(PMC *d); 
     480    } 
     481 
    465482    METHOD exp() { 
    466483        PMC * const d  = Parrot_pmc_new(INTERP, VTABLE_type(INTERP, SELF)); 
    467484        SET_ATTR_fv(INTERP, d, exp(SELF.get_number())); 
  • t/pmc/float.t

     
    1616 
    1717=cut 
    1818 
    19 .const int TESTS = 162 
     19.const int TESTS = 166 
    2020.const num PRECISION = 0.000001 
    2121 
    2222.sub 'test' :main 
     
    7878    log10_method() 
    7979    log2_method() 
    8080    sec_method() 
     81    csc_method() 
    8182    sech_method() 
    8283    sin_method() 
    8384    sinh_method() 
    8485    tan_method() 
     86    cot_method() 
    8587    tanh_method() 
    8688    sqrt_method() 
    8789.end 
     
    9981000    test_method('sec', 0.5, 1.139493927) 
    9991001.end 
    10001002 
     1003.sub 'csc_method' 
     1004    test_method('csc', 0.5, 2.0858296) 
     1005    test_method('csc', 1.0, 1.1883951) 
     1006.end 
     1007 
    10011008.sub 'sech_method' 
    10021009    test_method('sech', 0.0, 1.0) 
    10031010    test_method('sech', 0.5, 0.886818884) 
     
    10181025    test_method('tan', 0.5, 0.546302490) 
    10191026.end 
    10201027 
     1028.sub 'cot_method' 
     1029    test_method('cot', 0.5, 1.8304877) 
     1030    test_method('cot', 1.0, 0.64209262) 
     1031.end 
     1032 
    10211033.sub 'tanh_method' 
    10221034    test_method('tanh', 0.0, 0.0) 
    10231035    test_method('tanh', 0.5, 0.462117157) 
  • t/dynoplibs/trans.t

     
    2323    .local num epsilon 
    2424    epsilon = _epsilon() 
    2525 
    26     plan(69) 
     26    plan(77) 
    2727 
    2828    test_sin_n(epsilon) 
    2929    test_sin_i(epsilon) 
     
    3131    test_cos_i(epsilon) 
    3232    test_tan_n(epsilon) 
    3333    test_tan_i(epsilon) 
     34    test_cot_n(epsilon) 
     35    test_cot_i(epsilon) 
    3436    test_sec_n(epsilon) 
    3537    test_sec_i(epsilon) 
     38    test_csc_n(epsilon) 
     39    test_csc_i(epsilon) 
    3640    test_atan_n(epsilon) 
    3741    test_atan_i(epsilon) 
    3842    test_asin_n(epsilon) 
     
    137141    is($N0, 1.557408, "tan(1)", epsilon) 
    138142.end 
    139143 
     144.sub test_cot_n 
     145    .param num epsilon 
     146 
     147    $N0 = cot 0.5 
     148    is($N0,  1.8305, "cot(0.5)", epsilon) 
     149 
     150    $N0 = cot 1.0 
     151    is($N0,  0.64209, "cot(1.0)", epsilon) 
     152.end 
     153 
     154.sub test_cot_i 
     155    .param num epsilon 
     156 
     157    $N0 = cot 1 
     158    is($N0, 0.64209, "cot(1)", epsilon) 
     159 
     160    $N0 = cot 2 
     161    is($N0,  -0.45766, "cot(2)", epsilon) 
     162.end 
     163 
    140164.sub test_sec_n 
    141165    .param num epsilon 
    142166 
     
    153177    is($N1, 1.850816, "sec(1)", epsilon) 
    154178.end 
    155179 
     180.sub test_csc_n 
     181    .param num epsilon 
     182 
     183    $N0 = csc 0.5 
     184    is($N0,   2.0858, "csc(0.5)", epsilon) 
     185 
     186    $N0 = csc 1.0 
     187    is($N0,  1.1884, "csc(1.0)", epsilon) 
     188.end 
     189 
     190.sub test_csc_i 
     191    .param num epsilon 
     192 
     193    $N0 = csc 1 
     194    is($N0, 1.1884, "csc(1)", epsilon) 
     195 
     196    $N0 = csc 2 
     197    is($N0,   1.0998, "csc(2)", epsilon) 
     198.end 
     199 
    156200.sub test_atan_n 
    157201    .param num epsilon 
    158202 
  • t/dynoplibs/trans-infnan.t

     
    2020 
    2121.sub main :main 
    2222    .include 'test_more.pir' 
    23     plan(67) 
     23    plan(70) 
    2424 
    2525    test_exp() 
    2626    test_sin() 
     
    3636    test_coth() 
    3737    test_acot() 
    3838    test_sec() 
     39    test_csc() 
    3940    test_sech() 
    4041    test_asec() 
    4142    test_ln() 
     
    232233    is($N1, 'NaN', '... sec NaN') 
    233234.end 
    234235 
     236.sub test_csc 
     237    $N0 = 'Inf' 
     238    $N1 = csc $N0 
     239    is($N1, 'NaN', 'csc: csc Inf') 
     240    $N0 = '-Inf' 
     241    $N1 = csc $N0 
     242    is($N1, 'NaN', '... csc -Inf') 
     243    $N0 = 'NaN' 
     244    $N1 = csc $N0 
     245    is($N1, 'NaN', '... csc NaN') 
     246.end 
     247 
    235248.sub test_sech 
    236249    $N0 = 'Inf' 
    237250    $N1 = sech $N0 
     
    295308    is($N1, 'NaN', '... log2 -Inf') 
    296309.end 
    297310 
    298  
    299311.sub test_cot 
    300312    $N0 = 'Inf' 
    301     #$N1 = cot $N0 
    302     #is($N1, 'NaN', 'cot: cot Inf') 
    303     todo(0, 'cot Inf', 'cot/coth/acot not implemented for real numbers') 
     313    $N1 = cot $N0 
     314    is($N1, 'NaN', 'cot: cot Inf') 
    304315    $N0 = '-Inf' 
    305     #$N1 = cot $N0 
    306     #is($N1, 'NaN', '... cot -Inf') 
    307     todo(0, 'cot -Inf', 'cot/coth/acot not implemented for real numbers') 
     316    $N1 = cot $N0 
     317    is($N1, 'NaN', '... cot -Inf') 
    308318    $N0 = 'NaN' 
    309     #$N1 = cot $N0 
    310     #is($N1, 'NaN', '... cot NaN') 
    311     todo(0, 'cot NaN', 'cot/coth/acot not implemented for real numbers') 
     319    $N1 = cot $N0 
     320    is($N1, 'NaN', '... cot NaN') 
    312321.end 
    313322 
    314323.sub test_pow