Changeset 10003

Show
Ignore:
Timestamp:
04/17/06 22:18:01 (3 years ago)
Author:
yiyihu
Message:

Perl 6 version of round_random, round_up, round_down implemented.
Now, Math::Basic rounding suite according to
http://www.pldesignline.com/howto/showArticle.jhtml?articleID=175801189
almost finished.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • misc/S29_round.pl

    r10001 r10003  
    5959 
    6060our Int multi Num::round_random (Num $x) { 
    61         ... 
     61        my @l = ( 
     62                { $^a.round_half_up: symmetrical => $^b }, 
     63                { $^a.round_half_down: symmetrical => $^b }, 
     64                { $^a.round_half_even }, 
     65                { $^a.round_half_odd }, 
     66 
     67#               { $^a.round_half_alternate }, 
     68#               { $^a.round_half_random }, 
     69 
     70                { $^a.round_half_ceiling }, 
     71                { $^a.round_toward_zero }, 
     72                { $^a.round_away_from_zero }, 
     73 
     74#               { $^a.round_up: symmetrical => $^b }, 
     75#               { $^a.round_down: symmetrical => $^b }, 
     76                ); 
     77        my $sym_flag = (int(rand() * 10)) % 2; 
     78        my $selector = (int(rand() * 100)) % @l.elems; 
     79 
     80        @l[$selector]($x, $sym_flag); 
    6281} 
    6382 
     
    86105} 
    87106 
    88 our Int multi Num::round_up (Num $x) { 
    89         ... 
     107our Int multi Num::round_up (Num $x, int $symmetrical? = 1) { 
     108        $symmetrical ?? $x.round_away_from_zero 
     109                !! $x.round_ceiling 
    90110} 
    91111 
    92 our Int multi Num::round_down (Num $x) { 
     112our Int multi Num::round_down (Num $x, int $symmetrical? = 1) { 
     113        $symmetrical ?? $x.round_toward_zero 
     114                !! $x.round_floor 
     115} 
     116 
     117our Int multi Num::truncation (Num $x) { 
    93118        ... 
    94119}