5 src/builtins/any_num.pir - C<Num>-like functions and methods for C<Any>
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,
22 .sub 'onload' :anon :init :load
23 $P0 = get_hll_namespace ['Any']
24 '!EXPORT'('abs cis int log polar sqrt truncate unpolar', 'from'=>$P0)
26 ## pre-seed a random number generator
28 set_hll_global ['Any'], '$!random', $P0
38 .sub 'abs' :method :multi(_)
50 .sub 'cis' :method :multi(_)
51 .return 'unpolar'(1.0, self)
55 .sub 'int' :method :multi(_)
56 .return self.'truncate'()
61 our Num multi Num::log ( Num $x: Num :$base )
62 our Num multi Math::Basic::log ( Num $x, Num :$base )
64 Logarithm of base C<$base>, default Natural. Calling with C<$x == 0> is an
69 .sub 'log' :method :multi(_)
81 .sub 'polar' :method :multi(_)
83 .return 'list'($N0, 0)
94 ## 0-argument test, RT#56366
96 die "too many arguments passed - 0 params expected"
98 $P0 = get_hll_global ['Any'], '$!random'
106 $P0 = get_hll_global ['Any'], '$!random'
118 .sub 'sqrt' :method :multi(_)
131 .param num seed :optional
132 .param int has_seed :opt_flag
133 if has_seed goto have_seed
136 $P0 = get_hll_global ['Any'], '$!random'
146 $P0 = get_hll_global ['Any'], '$!random'
159 .sub 'truncate' :method :multi(_)
161 if $N0 == 0 goto done
162 if $N0 < 0 goto num_ceil
173 =item unpolar($angle)
177 .sub 'unpolar' :method
182 result = new 'Complex'
203 # vim: expandtab shiftwidth=4 ft=pir: