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

« back to all changes in this revision

Viewing changes to src/builtins/any-num.pir

  • 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
 
## $Id$
2
 
 
3
 
=head1 NAME
4
 
 
5
 
src/builtins/any_num.pir -  C<Num>-like functions and methods for C<Any>
6
 
 
7
 
=head1 DESCRIPTION
8
 
 
9
 
This file implements the methods and functions of C<Any> that
10
 
are most closely associated with the C<Num> class or role.
11
 
We place them here instead of F<src/classes/Any.pir> to keep
12
 
the size of that file down and to emphasize their generic,
13
 
"built-in" nature.
14
 
 
15
 
=head2 Methods
16
 
 
17
 
=over 4
18
 
 
19
 
=cut
20
 
 
21
 
.namespace []
22
 
.loadlib 'math_ops'
23
 
.sub 'onload' :anon :init :load
24
 
    $P0 = get_hll_namespace ['Any']
25
 
    '!EXPORT'('int,polar,truncate', 'from'=>$P0)
26
 
 
27
 
    ##  pre-seed a random number generator
28
 
    'srand'()
29
 
.end
30
 
 
31
 
.namespace ['Any']
32
 
.sub 'int' :method :multi(_)
33
 
    "die"("the int() sub and .int method have been replaced by the .Int method")
34
 
.end
35
 
 
36
 
.namespace ['Any']
37
 
.sub 'Int' :method :multi(_)
38
 
    .tailcall self.'truncate'()
39
 
.end
40
 
 
41
 
 
42
 
=item polar
43
 
 
44
 
=cut
45
 
 
46
 
.namespace ['Any']
47
 
.sub 'polar' :method :multi(_)
48
 
    $N0 = self
49
 
    .tailcall 'list'($N0, 0)
50
 
.end
51
 
 
52
 
 
53
 
=item srand()
54
 
 
55
 
=cut
56
 
 
57
 
.namespace []
58
 
.sub 'srand'
59
 
    .param num seed            :optional
60
 
    .param int has_seed        :opt_flag
61
 
    if has_seed goto have_seed
62
 
    seed = time
63
 
  have_seed:
64
 
    srand seed
65
 
    .return ()
66
 
.end
67
 
 
68
 
.namespace ['Any']
69
 
.sub 'srand' :method
70
 
    $N0 = self
71
 
    srand $N0
72
 
    .return ()
73
 
.end
74
 
 
75
 
 
76
 
=item truncate()
77
 
 
78
 
=item int
79
 
 
80
 
=cut
81
 
 
82
 
.namespace ['Any']
83
 
.sub 'truncate' :method :multi(_)
84
 
    $N0 = self
85
 
    if $N0 == 0 goto done
86
 
    if $N0 < 0 goto num_ceil
87
 
    floor $N0
88
 
    goto done
89
 
  num_ceil:
90
 
    ceil $N0
91
 
  done:
92
 
    $I0 = $N0
93
 
    .return ($I0)
94
 
.end
95
 
 
96
 
=back
97
 
 
98
 
=cut
99
 
 
100
 
# Local Variables:
101
 
#   mode: pir
102
 
#   fill-column: 100
103
 
# End:
104
 
# vim: expandtab shiftwidth=4 ft=pir: