Changeset 5385

Show
Ignore:
Timestamp:
07/11/05 03:51:05 (3 years ago)
Author:
mugwump
svk:copy_cache_prev:
7349
Message:

Add a few more tests to rounding tests, and make tests pass by adding to Prelude.pm

Files:
2 modified

Legend:

Unmodified
Added
Removed
  • src/perl6/Prelude.pm

    r5384 r5385  
    11module Prelude-0.0.1; 
    22 
     3#use Test; 
    34use v6; 
    45 
     
    232233} 
    233234 
     235multi sub Num::round_gen(Int $n, Code $corner) returns Int { $n } 
     236multi sub Num::round_gen(Num $n, Code $corner) returns Int { 
     237    if (int($n) == $n) { 
     238        return int($n); 
     239    } else { 
     240        return $corner($n); 
     241    } 
     242} 
     243 
     244sub Num::do_round($n) { ($n < 0) ?? int( $n - 0.5) :: int( $n + 0.5); } 
     245sub Num::round { Num::round_gen($^n, &Num::do_round) } 
     246 
     247sub Num::truncate { int($^n) } 
     248&Num::trunc ::= &Num::truncate; 
     249 
     250sub Num::do_ceil($n) { ($n < 0) ?? (-int(-$n)) :: int($n + 1) } 
     251sub Num::ceiling { Num::round_gen($^n, &Num::do_ceil) } 
     252&Num::ceil ::= &Num::ceiling; 
     253 
     254sub Num::do_floor($n) { ($n < 0) ?? (-int(1-$n)) :: int($n) } 
     255sub Num::floor { Num::round_gen($^n, &Num::do_floor) } 
     256 
    234257sub *sprintf ($fmt,*@args) { 
    235258    my $flen = $fmt.chars; 
  • t/builtins/math/rounders.t

    r5376 r5385  
    44use Test; 
    55 
    6 plan 28; 
     6plan 36; 
    77 
    88=pod 
     
    1313 
    1414my %tests = 
    15     ( ceil  => [ [ 1.5, 2 ], [ 2, 2 ], [ 1.4999, 2 ], 
    16                  [ -0.1, 0 ], [ -1, -1 ], [ -0.9, 0 ], 
    17                  [ -0.5, 0 ] ], 
     15    ( ceiling => [ [ 1.5, 2 ], [ 2, 2 ], [ 1.4999, 2 ], 
     16                 [ -0.1, 0 ], [ -1, -1 ], [ -5.9, -5 ], 
     17                 [ -0.5, 0 ], [ -0.499, 0 ], [ -5.499, -5 ] ], 
    1818      floor => [ [ 1.5, 1 ], [ 2, 2 ], [ 1.4999, 1 ], 
    19                  [ -0.1, -1 ], [ -1, -1 ], [ -0.9, -1 ], 
    20                  [ -0.5, -1 ] ], 
     19                 [ -0.1, -1 ], [ -1, -1 ], [ -5.9, -6 ], 
     20                 [ -0.5, -1 ], [ -0.499, -1 ], [ -5.499, -6 ] ], 
    2121      round => [ [ 1.5, 2 ], [ 2, 2 ], [ 1.4999, 1 ], 
    22                  [ -0.1, 0 ], [ -1, -1 ], [ -0.9, -1 ], 
    23                  [ -0.5, -1 ] ], 
    24       trunc => [ [ 1.5, 1 ], [ 2, 2 ], [ 1.4999, 1 ], 
    25                  [ -0.1, 0 ], [ -1, -1 ], [ -0.9, 0 ], 
    26                  [ -0.5, 0 ] ], 
     22                 [ -0.1, 0 ], [ -1, -1 ], [ -5.9, -6 ], 
     23                 [ -0.5, -1 ], [ -0.499, 0 ], [ -5.499, -5 ] ], 
     24      truncate => [ [ 1.5, 1 ], [ 2, 2 ], [ 1.4999, 1 ], 
     25                 [ -0.1, 0 ], [ -1, -1 ], [ -5.9, -5 ], 
     26                 [ -0.5, 0 ], [ -0.499, 0 ], [ -5.499, -5 ] ], 
    2727    ); 
    2828