~ubuntu-branches/ubuntu/precise/rakudo/precise

« back to all changes in this revision

Viewing changes to src/setting/Int.pm

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghedini
  • Date: 2011-05-17 11:31:09 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110517113109-rmfir654u1axbpt4
Tags: 0.1~2011.04-1
* New upstream release (Closes: #601862, #585762, #577502)
* New maintainer
* Switch to 3.0 (quilt) format
* Update dependencies (Closes: #584498)
* Update debian/copyright to lastest DEP5 revision
* Do not generate/install perl6 manpage (now done by the build system)
* Enable tests
* Bump Standards-Version to 3.9.2 (no changes needed)
* Do not install extra LICENSE files and duplicated docs
* Remove debian/clean (no more needed)
* Add Vcs-* fields in debian/control
* Rewrite (short) description
* Update upstream copyright years
* Upload to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
class Int is also {
2
 
    multi method abs() {
3
 
        Q:PIR {
4
 
            $I0 = self
5
 
            $I0 = abs $I0
6
 
            %r  = box $I0
7
 
        }
8
 
    }
9
 
    our Int multi method Int() { self }
10
 
 
11
 
    our Num multi method Num() {
12
 
        Q:PIR {
13
 
            $N0 = self
14
 
            %r = box $N0
15
 
        }
16
 
    }
17
 
 
18
 
    our Rat multi method Rat() { Rat.new(self, 1); }
19
 
 
20
 
    our Complex multi method Complex() { Complex.new(self, 0); }
21
 
 
22
 
    our Str multi method Str() {
23
 
        ~self;
24
 
    }
25
 
 
26
 
    # Most of the trig functions for Int are in Any-num.pm, but
27
 
    # sec is a special case.
28
 
    our Num multi method sec($base = 'radians') {
29
 
        self.Num.sec($base);
30
 
    }
31
 
 
32
 
    our Complex multi method unpolar($angle) is export {
33
 
        Complex.new(self.Num * $angle.cos("radians"), self.Num * $angle.sin("radians"));
34
 
    }
35
 
 
36
 
    our Int multi method sign() {
37
 
        self.Num.sign
38
 
    }
39
 
}
40
 
 
41
 
multi sub abs(Int $x) { $x.abs }
42
 
 
43
 
multi sub infix:<+>(Int $a, Int $b) {
44
 
    Q:PIR {
45
 
        $P0 = find_lex '$a'
46
 
        $N0 = $P0
47
 
        $P1 = find_lex '$b'
48
 
        $N1 = $P1
49
 
        $N2 = $N0 + $N1
50
 
        %r = '!upgrade_to_num_if_needed'($N2)
51
 
    }
52
 
}
53
 
 
54
 
multi sub infix:<->(Int $a, Int $b) {
55
 
    Q:PIR {
56
 
        $P0 = find_lex '$a'
57
 
        $N0 = $P0
58
 
        $P1 = find_lex '$b'
59
 
        $N1 = $P1
60
 
        $N2 = $N0 - $N1
61
 
        %r = '!upgrade_to_num_if_needed'($N2)
62
 
    }
63
 
}
64
 
 
65
 
multi sub infix:<*>(Int $a, Int $b) {
66
 
    Q:PIR {
67
 
        $P0 = find_lex '$a'
68
 
        $N0 = $P0
69
 
        $P1 = find_lex '$b'
70
 
        $N1 = $P1
71
 
        $N2 = $N0 * $N1
72
 
        %r = '!upgrade_to_num_if_needed'($N2)
73
 
    }
74
 
}
75
 
 
76
 
multi sub infix:<div>(Int $a, Int $b) {
77
 
    Q:PIR {
78
 
        $P0 = find_lex '$a'
79
 
        $I0 = $P0
80
 
        $P1 = find_lex '$b'
81
 
        $I1 = $P1
82
 
        $I2 = $I0 / $I1
83
 
        %r = box $I2
84
 
    }
85
 
}
86
 
 
87
 
multi sub infix:<%>(Int $a, Int $b) {
88
 
    Q:PIR {
89
 
        $P0 = find_lex '$a'
90
 
        $N0 = $P0
91
 
        $P1 = find_lex '$b'
92
 
        $N1 = $P1
93
 
        $N2 = mod $N0, $N1
94
 
        %r = '!upgrade_to_num_if_needed'($N2)
95
 
    }
96
 
}
97
 
 
98
 
multi sub infix:<**>(Int $a, Int $b) {
99
 
    Q:PIR {
100
 
        $P0 = find_lex '$a'
101
 
        $N0 = $P0
102
 
        $P1 = find_lex '$b'
103
 
        $N1 = $P1
104
 
        $N2 = pow $N0, $N1
105
 
        %r = '!upgrade_to_num_if_needed'($N2)
106
 
    }
107
 
}
108
 
 
109
 
multi sub prefix:<->(Int $a) {
110
 
    Q:PIR {
111
 
        $P0 = find_lex '$a'
112
 
        $N0 = $P0
113
 
        $N0 = neg $N0
114
 
        %r = '!upgrade_to_num_if_needed'($N0)
115
 
    }
116
 
}
117