| 1 | package Language::Farnsworth::Functions::StdMath; | ||
| 2 | |||
| 3 | 4 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 4 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 4 | ▶ | use Math::Pari; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 4 | ▶ | use Data::Dumper; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 4 | ▶ | use Language::Farnsworth::Value::Pari; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 4 | ▶ | use Language::Farnsworth::Value::Array; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | 4 | ▶ | use Language::Farnsworth::Value::Lambda; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | 4 | ▶ | use Language::Farnsworth::Value::Boolean; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | 4 | ▶ | use Language::Farnsworth::Error; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 13 | |||
| 14 | sub init | ||
| 15 | 4 | ▶ | { |
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 16 | 4 | my $env = shift; | |
| 17 | |||
| 18 | 4 | my $array = new Language::Farnsworth::Value::Array([]); | |
| 19 | 4 | my $string = new Language::Farnsworth::Value::String(""); | |
| 20 | 4 | my $lambda = new Language::Farnsworth::Value::Lambda(); | |
| 21 | 4 | my $number = new Language::Farnsworth::Value::Pari(0); | |
| 22 | |||
| 23 | 4 | $env->{funcs}->addfunc("ln", [["in", undef, $number, 0]],\&log,$env); | |
| 24 | 4 | $env->eval("log{x isa 1} := {ln[x]/ln[10]}"); | |
| 25 | 4 | $env->{funcs}->addfunc("sin", [["in", undef, $number, 0]],\&sin,$env); | |
| 26 | 4 | $env->{funcs}->addfunc("cos", [["in", undef, $number, 0]],\&cos,$env); | |
| 27 | 4 | $env->{funcs}->addfunc("tan", [["in", undef, $number, 0]],\&tan,$env); | |
| 28 | 4 | $env->eval("csc{x isa 1} := {1/sin[x]}"); | |
| 29 | 4 | $env->eval("sec{x isa 1} := {1/cos[x]}"); | |
| 30 | 4 | $env->eval("cot{x isa 1} := {1/tan[x]}"); | |
| 31 | 4 | $env->eval("atan2{x isa 1,y isa 1} := {var s=x^2+y^2; var r=y+x i; -i * ln[r / sqrt[s]]}"); | |
| 32 | 4 | $env->{funcs}->addfunc("sinh", [["in", undef, $number, 0]],\&sinh,$env); | |
| 33 | 4 | $env->{funcs}->addfunc("cosh", [["in", undef, $number, 0]],\&cosh,$env); | |
| 34 | 4 | $env->{funcs}->addfunc("tanh", [["in", undef, $number, 0]],\&tanh,$env); | |
| 35 | 4 | $env->{funcs}->addfunc("arcsin", [["in", undef, $number, 0]],\&arcsin,$env); | |
| 36 | 4 | $env->{funcs}->addfunc("arccos", [["in", undef, $number, 0]],\&arccos,$env); | |
| 37 | 4 | $env->{funcs}->addfunc("arctan", [["in", undef, $number, 0]],\&arctan,$env); | |
| 38 | 4 | $env->{funcs}->addfunc("arcsinh", [["in", undef, $number, 0]],\&arcsinh,$env); | |
| 39 | 4 | $env->{funcs}->addfunc("arccosh", [["in", undef, $number, 0]],\&arccosh,$env); | |
| 40 | 4 | $env->{funcs}->addfunc("arctanh", [["in", undef, $number, 0]],\&arctanh,$env); | |
| 41 | 4 | $env->{funcs}->addfunc("asin", [["in", undef, $number, 0]],\&arcsin,$env); | |
| 42 | 4 | $env->{funcs}->addfunc("acos", [["in", undef, $number, 0]],\&arccos,$env); | |
| 43 | 4 | $env->{funcs}->addfunc("atan", [["in", undef, $number, 0]],\&arctan,$env); | |
| 44 | 4 | $env->{funcs}->addfunc("asinh", [["in", undef, $number, 0]],\&arcsinh,$env); | |
| 45 | 4 | $env->{funcs}->addfunc("acosh", [["in", undef, $number, 0]],\&arccosh,$env); | |
| 46 | 4 | $env->{funcs}->addfunc("atanh", [["in", undef, $number, 0]],\&arctanh,$env); | |
| 47 | 4 | $env->{funcs}->addfunc("abs", [["in", undef, undef, 0]],\&abs,$env); | |
| 48 | 4 | $env->{funcs}->addfunc("floor", [["in", undef, undef, 0]],\&floor,$env); | |
| 49 | 4 | $env->{funcs}->addfunc("ceil", [["in", undef, undef, 0]],\&ceil,$env); | |
| 50 | 4 | $env->{funcs}->addfunc("int", [["in", undef, undef, 0]],\&int,$env); | |
| 51 | 4 | $env->{funcs}->addfunc("rint", [["in", undef, undef, 0]],\&rint,$env); | |
| 52 | 4 | $env->eval("round{x, d isa 1} := {var m = x * 10 ** d; rint[m] * 10 ** -d+0.0};"); | |
| 53 | 4 | $env->{funcs}->addfunc("trunc", [["in", undef, undef, 0]],\&int,$env); | |
| 54 | 4 | $env->{funcs}->addfunc("numerator", [["in", undef, $number, 0]],\&numerator,$env); | |
| 55 | 4 | $env->{funcs}->addfunc("denominator", [["in", undef, $number, 0]],\&denominator,$env); | |
| 56 | |||
| 57 | 4 | $env->{funcs}->addfunc("real", [["in", undef, $number, 0]],\&real,$env); | |
| 58 | 4 | $env->{funcs}->addfunc("imag", [["in", undef, $number, 0]],\&imag,$env); | |
| 59 | 4 | $env->eval("imaginary{x isa 1} := imag[x]"); | |
| 60 | 4 | $env->{funcs}->addfunc("conj", [["in", undef, $number, 0]],\&conj,$env); | |
| 61 | 4 | $env->{funcs}->addfunc("norm", [["in", undef, $number, 0]],\&norm,$env); | |
| 62 | |||
| 63 | 4 | $env->{funcs}->addfunc("isprime", [["in", undef, $number, 0]],\&isprime,$env); | |
| 64 | 4 | $env->{funcs}->addfunc("prime", [["in", undef, $number, 0]],\&prime,$env); | |
| 65 | 4 | $env->{funcs}->addfunc("precprime", [["in", undef, $number, 0]],\&precprime,$env); | |
| 66 | 4 | $env->{funcs}->addfunc("nextprime", [["in", undef, $number, 0]],\&nextprime,$env); | |
| 67 | 4 | $env->{funcs}->addfunc("factor", [["in", undef, $number, 0]],\&factor,$env); | |
| 68 | |||
| 69 | 4 | $env->{funcs}->addfunc("randmax", [["in", undef, $number, 0]],\&randmax,$env); | |
| 70 | 4 | $env->{funcs}->addfunc("getrseed", [[]],\&getrseed,$env); | |
| 71 | 4 | $env->{funcs}->addfunc("setrseed", [[]],\&setrseed,$env); | |
| 72 | 4 | $env->eval("random{} := randmax[10**30]/10.0**30"); | |
| 73 | 4 | $env->eval("quad{a isa 1, b isa 1, c isa 1} := [(-b + sqrt[b^2 - 4 a c]) / 2a, (-b - sqrt[b^2 - 4 a c]) / 2a]"); | |
| 74 | 4 | $env->eval("quadratic{a, b, c} := quad[a,b,c]"); | |
| 75 | 4 | $env->eval("randrange{x,y} := {var min=min[x,y]; var max=max[x,y]; min+randmax[max-min+1]}"); | |
| 76 | |||
| 77 | 4 | $env->{funcs}->addfunc("gcd", [["left", undef, $number, 0],["right", undef, $number, 0]],\&gcd,$env); | |
| 78 | 4 | $env->{funcs}->addfunc("lcm", [["left", undef, $number, 0],["right", undef, $number, 0]],\&lcm,$env); | |
| 79 | |||
| 80 | #these functions are simple enough to implement in farnsworth itself, so why not | ||
| 81 | 4 | $env->{funcs}->addfunc("sqrt", [["in", undef, undef, 0]],\&sqrt,$env); #putting in like this to see if it brings better luck | |
| 82 | 4 | $env->eval("i := sqrt[-1]"); #since we have a better sqrt, use it to make a better i | |
| 83 | # $env->eval("sqrt{x} := {x ^ 0.5}"); | ||
| 84 | 4 | $env->eval("exp{x isa 1} := {e ^ x}"); | |
| 85 | 4 | $env->eval("inv{x} := {1/x}"); | |
| 86 | 4 | $env->eval("recip{x} := {1/x}"); | |
| 87 | |||
| 88 | #$env->eval("_tohex{x isa 1} := { if(x < 16) { substrLen[\"0123456789abcdef\", x, 1] } else { _tohex[floor[x/16]] + _tohex[x%16] } }; tohex{x isa 1} := {\"0x\"+_tohex[x]}"); | ||
| 89 | |||
| 90 | } | ||
| 91 | |||
| 92 | sub sqrt | ||
| 93 | 5 | ▶ | { |
|
Subroutine
sqrt: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 94 | #with an array we give the number of elements, with a string we give the length of the string | ||
| 95 | 5 | my ($args, $eval, $branches)= @_; | |
| 96 | |||
| 97 | 5 | my $input = $eval->{vars}->getvar("in"); #i should clean this up more too | |
| 98 | |||
| 99 | 5 | my $units = $input->getdimen(); | |
| 100 | 5 | $units = $units->mult(PARI '1/2'); #half them all! | |
| 101 | |||
| 102 | 5 | return Language::Farnsworth::Value::Pari->new(Math::Pari::sqrt($input->getpari()), $units); | |
| 103 | } | ||
| 104 | |||
| 105 | sub sin | ||
| 106 | 1 | ▶ | { |
|
Subroutine
sin: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 107 | #with an array we give the number of elements, with a string we give the length of the string | ||
| 108 | 1 | my ($args, $eval, $branches)= @_; | |
| 109 | |||
| 110 | 1 | my $input = $eval->{vars}->getvar("in"); #i should clean this up more too | |
| 111 | |||
| 112 | 1 | return Language::Farnsworth::Value::Pari->new(Math::Pari::sin($input->getpari())); | |
| 113 | } | ||
| 114 | |||
| 115 | sub cos | ||
| 116 | 0 | ▶ | { |
|
Subroutine
cos: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 117 | #with an array we give the number of elements, with a string we give the length of the string | ||
| 118 | 0 | my ($args, $eval, $branches)= @_; | |
| 119 | |||
| 120 | 0 | my $input = $eval->{vars}->getvar("in"); #i should clean this up more too | |
| 121 | |||
| 122 | 0 | return Language::Farnsworth::Value::Pari->new(Math::Pari::cos($input->getpari())); | |
| 123 | } | ||
| 124 | |||
| 125 | sub tan | ||
| 126 | 0 | ▶ | { |
|
Subroutine
tan: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 127 | #with an array we give the number of elements, with a string we give the length of the string | ||
| 128 | 0 | my ($args, $eval, $branches)= @_; | |
| 129 | |||
| 130 | 0 | my $input = $eval->{vars}->getvar("in"); #i should clean this up more too | |
| 131 | |||
| 132 | 0 | return Language::Farnsworth::Value::Pari->new(Math::Pari::tan($input->getpari())); | |
| 133 | } | ||
| 134 | |||
| 135 | sub arcsin | ||
| 136 | 0 | ▶ | { |
|
Subroutine
arcsin: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 137 | #with an array we give the number of elements, with a string we give the length of the string | ||
| 138 | 0 | my ($args, $eval, $branches)= @_; | |
| 139 | |||
| 140 | 0 | my $input = $eval->{vars}->getvar("in"); #i should clean this up more too | |
| 141 | |||
| 142 | 0 | return Language::Farnsworth::Value::Pari->new(Math::Pari::asin($input->getpari())); | |
| 143 | } | ||
| 144 | |||
| 145 | sub arccos | ||
| 146 | 0 | ▶ | { |
|
Subroutine
arccos: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 147 | #with an array we give the number of elements, with a string we give the length of the string | ||
| 148 | 0 | my ($args, $eval, $branches)= @_; | |
| 149 | |||
| 150 | 0 | my $input = $eval->{vars}->getvar("in"); #i should clean this up more too | |
| 151 | |||
| 152 | 0 | return Language::Farnsworth::Value::Pari->new(Math::Pari::acos($input->getpari())); | |
| 153 | } | ||
| 154 | |||
| 155 | sub arctan | ||
| 156 | 0 | ▶ | { |
|
Subroutine
arctan: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 157 | #with an array we give the number of elements, with a string we give the length of the string | ||
| 158 | 0 | my ($args, $eval, $branches)= @_; | |
| 159 | |||
| 160 | 0 | my $input = $eval->{vars}->getvar("in"); #i should clean this up more too | |
| 161 | |||
| 162 | 0 | return Language::Farnsworth::Value::Pari->new(Math::Pari::atan($input->getpari())); | |
| 163 | } | ||
| 164 | |||
| 165 | sub sinh | ||
| 166 | 0 | ▶ | { |
|
Subroutine
sinh: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 167 | #with an array we give the number of elements, with a string we give the length of the string | ||
| 168 | 0 | my ($args, $eval, $branches)= @_; | |
| 169 | |||
| 170 | 0 | my $input = $eval->{vars}->getvar("in"); #i should clean this up more too | |
| 171 | |||
| 172 | 0 | return Language::Farnsworth::Value::Pari->new(Math::Pari::sinh($input->getpari())); | |
| 173 | } | ||
| 174 | |||
| 175 | sub cosh | ||
| 176 | 0 | ▶ | { |
|
Subroutine
cosh: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 177 | #with an array we give the number of elements, with a string we give the length of the string | ||
| 178 | 0 | my ($args, $eval, $branches)= @_; | |
| 179 | |||
| 180 | 0 | my $input = $eval->{vars}->getvar("in"); #i should clean this up more too | |
| 181 | |||
| 182 | 0 | return Language::Farnsworth::Value::Pari->new(Math::Pari::cosh($input->getpari())); | |
| 183 | } | ||
| 184 | |||
| 185 | sub tanh | ||
| 186 | 0 | ▶ | { |
|
Subroutine
tanh: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 187 | #with an array we give the number of elements, with a string we give the length of the string | ||
| 188 | 0 | my ($args, $eval, $branches)= @_; | |
| 189 | |||
| 190 | 0 | my $input = $eval->{vars}->getvar("in"); #i should clean this up more too | |
| 191 | |||
| 192 | 0 | return Language::Farnsworth::Value::Pari->new(Math::Pari::tanh($input->getpari())); | |
| 193 | } | ||
| 194 | |||
| 195 | sub arcsinh | ||
| 196 | 0 | ▶ | { |
|
Subroutine
arcsinh: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 197 | #with an array we give the number of elements, with a string we give the length of the string | ||
| 198 | 0 | my ($args, $eval, $branches)= @_; | |
| 199 | |||
| 200 | 0 | my $input = $eval->{vars}->getvar("in"); #i should clean this up more too | |
| 201 | |||
| 202 | 0 | return Language::Farnsworth::Value::Pari->new(Math::Pari::asinh($input->getpari())); | |
| 203 | } | ||
| 204 | |||
| 205 | sub arccosh | ||
| 206 | 0 | ▶ | { |
|
Subroutine
arccosh: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 207 | #with an array we give the number of elements, with a string we give the length of the string | ||
| 208 | 0 | my ($args, $eval, $branches)= @_; | |
| 209 | |||
| 210 | 0 | my $input = $eval->{vars}->getvar("in"); #i should clean this up more too | |
| 211 | |||
| 212 | 0 | return Language::Farnsworth::Value::Pari->new(Math::Pari::acosh($input->getpari())); | |
| 213 | } | ||
| 214 | |||
| 215 | sub arctanh | ||
| 216 | 0 | ▶ | { |
|
Subroutine
arctanh: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 217 | #with an array we give the number of elements, with a string we give the length of the string | ||
| 218 | 0 | my ($args, $eval, $branches)= @_; | |
| 219 | |||
| 220 | 0 | my $input = $eval->{vars}->getvar("in"); #i should clean this up more too | |
| 221 | |||
| 222 | 0 | return Language::Farnsworth::Value::Pari->new(Math::Pari::atanh($input->getpari())); | |
| 223 | } | ||
| 224 | |||
| 225 | sub abs | ||
| 226 | 0 | ▶ | { |
|
Subroutine
abs: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 227 | #with an array we give the number of elements, with a string we give the length of the string | ||
| 228 | 0 | my ($args, $eval, $branches)= @_; | |
| 229 | |||
| 230 | 0 | my $input = $eval->{vars}->getvar("in"); #i should clean this up more too | |
| 231 | |||
| 232 | 0 | return Language::Farnsworth::Value::Pari->new(Math::Pari::abs($input->getpari()), $input->getdimen()); | |
| 233 | } | ||
| 234 | |||
| 235 | sub floor | ||
| 236 | 0 | ▶ | { |
|
Subroutine
floor: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 237 | #with an array we give the number of elements, with a string we give the length of the string | ||
| 238 | 0 | my ($args, $eval, $branches)= @_; | |
| 239 | |||
| 240 | 0 | my $input = $eval->{vars}->getvar("in"); #i should clean this up more too | |
| 241 | |||
| 242 | 0 | return Language::Farnsworth::Value::Pari->new(Math::Pari::floor($input->getpari()), $input->getdimen()); | |
| 243 | } | ||
| 244 | |||
| 245 | sub ceil | ||
| 246 | 0 | ▶ | { |
|
Subroutine
ceil: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 247 | #with an array we give the number of elements, with a string we give the length of the string | ||
| 248 | 0 | my ($args, $eval, $branches)= @_; | |
| 249 | |||
| 250 | 0 | my $input = $eval->{vars}->getvar("in"); #i should clean this up more too | |
| 251 | |||
| 252 | 0 | return Language::Farnsworth::Value::Pari->new(Math::Pari::ceil($input->getpari()), $input->getdimen()); | |
| 253 | } | ||
| 254 | |||
| 255 | sub int | ||
| 256 | 0 | ▶ | { |
|
Subroutine
int: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 257 | #with an array we give the number of elements, with a string we give the length of the string | ||
| 258 | 0 | my ($args, $eval, $branches)= @_; | |
| 259 | |||
| 260 | 0 | my $input = $eval->{vars}->getvar("in"); #i should clean this up more too | |
| 261 | |||
| 262 | 0 | my $e = PARI '0'; | |
| 263 | 0 | my $r = Language::Farnsworth::Value::Pari->new(Math::Pari::truncate($input->getpari(),$e), $input->getdimen()); | |
| 264 | 0 | debug 5, Data::Dumper->Dump([$r], ["\$r"]); | |
| 265 | 0 | return $r; | |
| 266 | } | ||
| 267 | |||
| 268 | sub numerator | ||
| 269 | 0 | ▶ | { |
|
Subroutine
numerator: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 270 | #with an array we give the number of elements, with a string we give the length of the string | ||
| 271 | 0 | my ($args, $eval, $branches)= @_; | |
| 272 | |||
| 273 | 0 | my $input = $eval->{vars}->getvar("in"); #i should clean this up more too | |
| 274 | |||
| 275 | #bug? should i make it pull the positive dimensions? | ||
| 276 | 0 | return Language::Farnsworth::Value::Pari->new(Math::Pari::numerator($input->getpari())); | |
| 277 | } | ||
| 278 | |||
| 279 | sub denominator | ||
| 280 | 0 | ▶ | { |
|
Subroutine
denominator: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 281 | #with an array we give the number of elements, with a string we give the length of the string | ||
| 282 | 0 | my ($args, $eval, $branches)= @_; | |
| 283 | |||
| 284 | 0 | my $input = $eval->{vars}->getvar("in"); #i should clean this up more too | |
| 285 | |||
| 286 | #bug? should i make it pull the negative dimensions? | ||
| 287 | 0 | return Language::Farnsworth::Value::Pari->new(Math::Pari::denominator($input->getpari())); | |
| 288 | } | ||
| 289 | |||
| 290 | sub real | ||
| 291 | 0 | ▶ | { |
|
Subroutine
real: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 292 | #with an array we give the number of elements, with a string we give the length of the string | ||
| 293 | 0 | my ($args, $eval, $branches)= @_; | |
| 294 | |||
| 295 | 0 | my $input = $eval->{vars}->getvar("in"); #i should clean this up more too | |
| 296 | |||
| 297 | 0 | return Language::Farnsworth::Value::Pari->new(Math::Pari::real($input->getpari()), $input->getdimen()); | |
| 298 | } | ||
| 299 | |||
| 300 | sub imag | ||
| 301 | 0 | ▶ | { |
|
Subroutine
imag: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 302 | #with an array we give the number of elements, with a string we give the length of the string | ||
| 303 | 0 | my ($args, $eval, $branches)= @_; | |
| 304 | |||
| 305 | 0 | my $input = $eval->{vars}->getvar("in"); #i should clean this up more too | |
| 306 | |||
| 307 | 0 | return Language::Farnsworth::Value::Pari->new(Math::Pari::imag($input->getpari()), $input->getdimen()); | |
| 308 | } | ||
| 309 | |||
| 310 | sub conj | ||
| 311 | 0 | ▶ | { |
|
Subroutine
conj: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 312 | #with an array we give the number of elements, with a string we give the length of the string | ||
| 313 | 0 | my ($args, $eval, $branches)= @_; | |
| 314 | |||
| 315 | 0 | my $input = $eval->{vars}->getvar("in"); #i should clean this up more too | |
| 316 | |||
| 317 | 0 | return Language::Farnsworth::Value::Pari->new(Math::Pari::conj($input->getpari()), $input->getdimen()); | |
| 318 | } | ||
| 319 | |||
| 320 | sub norm | ||
| 321 | 0 | ▶ | { |
|
Subroutine
norm: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 322 | #with an array we give the number of elements, with a string we give the length of the string | ||
| 323 | 0 | my ($args, $eval, $branches)= @_; | |
| 324 | |||
| 325 | 0 | my $input = $eval->{vars}->getvar("in"); #i should clean this up more too | |
| 326 | |||
| 327 | 0 | return Language::Farnsworth::Value::Pari->new(Math::Pari::norm($input->getpari()), $input->getdimen()); | |
| 328 | } | ||
| 329 | |||
| 330 | sub isprime | ||
| 331 | 0 | ▶ | { |
|
Subroutine
isprime: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 332 | #with an array we give the number of elements, with a string we give the length of the string | ||
| 333 | 0 | my ($args, $eval, $branches)= @_; | |
| 334 | |||
| 335 | 0 | my $input = $eval->{vars}->getvar("in"); #i should clean this up more too | |
| 336 | |||
| 337 | 0 | return Language::Farnsworth::Value::Boolean->new(Math::Pari::isprime($input->getpari())); | |
| 338 | } | ||
| 339 | |||
| 340 | sub prime | ||
| 341 | 0 | ▶ | { |
|
Subroutine
prime: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 342 | #with an array we give the number of elements, with a string we give the length of the string | ||
| 343 | 0 | my ($args, $eval, $branches)= @_; | |
| 344 | |||
| 345 | 0 | my $input = $eval->{vars}->getvar("in"); #i should clean this up more too | |
| 346 | |||
| 347 | 0 | return Language::Farnsworth::Value::Pari->new(Math::Pari::prime($input->getpari())); | |
| 348 | } | ||
| 349 | |||
| 350 | sub nextprime | ||
| 351 | 0 | ▶ | { |
|
Subroutine
nextprime: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 352 | #with an array we give the number of elements, with a string we give the length of the string | ||
| 353 | 0 | my ($args, $eval, $branches)= @_; | |
| 354 | |||
| 355 | 0 | my $input = $eval->{vars}->getvar("in"); #i should clean this up more too | |
| 356 | |||
| 357 | 0 | return Language::Farnsworth::Value::Pari->new(Math::Pari::nextprime($input->getpari())); | |
| 358 | } | ||
| 359 | |||
| 360 | sub precprime | ||
| 361 | 0 | ▶ | { |
|
Subroutine
precprime: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 362 | #with an array we give the number of elements, with a string we give the length of the string | ||
| 363 | 0 | my ($args, $eval, $branches)= @_; | |
| 364 | |||
| 365 | 0 | my $input = $eval->{vars}->getvar("in"); #i should clean this up more too | |
| 366 | |||
| 367 | 0 | return Language::Farnsworth::Value::Pari->new(Math::Pari::precprime($input->getpari())); | |
| 368 | } | ||
| 369 | |||
| 370 | sub factor | ||
| 371 | 0 | ▶ | { |
|
Subroutine
factor: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 372 | #with an array we give the number of elements, with a string we give the length of the string | ||
| 373 | 0 | my ($args, $eval, $branches)= @_; | |
| 374 | |||
| 375 | 0 | my $input = $eval->{vars}->getvar("in"); #i should clean this up more too | |
| 376 | |||
| 377 | 0 | return Language::Farnsworth::Value::Pari->new(Math::Pari::factor($input->getpari())); | |
| 378 | } | ||
| 379 | |||
| 380 | sub randmax | ||
| 381 | 0 | ▶ | { |
|
Subroutine
randmax: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 382 | #with an array we give the number of elements, with a string we give the length of the string | ||
| 383 | 0 | my ($args, $eval, $branches)= @_; | |
| 384 | |||
| 385 | 0 | my $input = $eval->{vars}->getvar("in"); #i should clean this up more too | |
| 386 | |||
| 387 | 0 | return Language::Farnsworth::Value::Pari->new(Math::Pari::random($input->getpari())); | |
| 388 | } | ||
| 389 | |||
| 390 | sub setrseed | ||
| 391 | 0 | ▶ | { |
|
Subroutine
setrseed: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 392 | #with an array we give the number of elements, with a string we give the length of the string | ||
| 393 | 0 | my ($args, $eval, $branches)= @_; | |
| 394 | |||
| 395 | 0 | my $input = $eval->{vars}->getvar("in"); #i should clean this up more too | |
| 396 | |||
| 397 | 0 | my $oldseed = Math::Pari::getrand(); | |
| 398 | 0 | Math::Pari::setrand($input->getpari()); | |
| 399 | |||
| 400 | 0 | return Language::Farnsworth::Value::Pari->new($oldseed); | |
| 401 | } | ||
| 402 | |||
| 403 | sub getrseed | ||
| 404 | 0 | ▶ | { |
|
Subroutine
getrseed: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 405 | #with an array we give the number of elements, with a string we give the length of the string | ||
| 406 | 0 | my ($args, $eval, $branches)= @_; | |
| 407 | |||
| 408 | 0 | return Language::Farnsworth::Value::Pari->new(Math::Pari::getrand()); | |
| 409 | } | ||
| 410 | |||
| 411 | sub rint | ||
| 412 | 0 | ▶ | { |
|
Subroutine
rint: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 413 | #with an array we give the number of elements, with a string we give the length of the string | ||
| 414 | 0 | my ($args, $eval, $branches)= @_; | |
| 415 | |||
| 416 | 0 | my $input = $eval->{vars}->getvar("in"); #i should clean this up more too | |
| 417 | |||
| 418 | #die "Argument to rint[] is not a numeric value" unless $input->isPARI(); | ||
| 419 | 0 | my $e = PARI '0'; | |
| 420 | 0 | return Language::Farnsworth::Value::Pari->new(Math::Pari::round($input->getpari(), $e), $input->getdimen()); | |
| 421 | } | ||
| 422 | |||
| 423 | sub gcd | ||
| 424 | 0 | ▶ | { |
|
Subroutine
gcd: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 425 | #with an array we give the number of elements, with a string we give the length of the string | ||
| 426 | 0 | my ($args, $eval, $branches)= @_; | |
| 427 | |||
| 428 | 0 | my $left = $eval->{vars}->getvar("left"); #i should clean this up more too | |
| 429 | 0 | my $right = $eval->{vars}->getvar("right"); #i should clean this up more too | |
| 430 | |||
| 431 | 0 | return Language::Farnsworth::Value::Pari->new(Math::Pari::gcd($left->getpari(), $right->getpari())); | |
| 432 | } | ||
| 433 | |||
| 434 | sub lcm | ||
| 435 | 0 | ▶ | { |
|
Subroutine
lcm: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 436 | #with an array we give the number of elements, with a string we give the length of the string | ||
| 437 | 0 | my ($args, $eval, $branches)= @_; | |
| 438 | |||
| 439 | 0 | my $left = $eval->{vars}->getvar("left"); #i should clean this up more too | |
| 440 | 0 | my $right = $eval->{vars}->getvar("right"); #i should clean this up more too | |
| 441 | |||
| 442 | 0 | return Language::Farnsworth::Value::Pari->new(Math::Pari::lcm($left->getpari(), $right->getpari())); | |
| 443 | } | ||
| 444 | |||
| 445 | sub log | ||
| 446 | 2 | ▶ | { |
|
Subroutine
log: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 447 | #with an array we give the number of elements, with a string we give the length of the string | ||
| 448 | 2 | my ($args, $eval, $branches)= @_; | |
| 449 | |||
| 450 | 2 | my $input = $eval->{vars}->getvar("in"); #i should clean this up more too | |
| 451 | |||
| 452 | 2 | return Language::Farnsworth::Value::Pari->new(Math::Pari::log($input->getpari())); | |
| 453 | } | ||
| 454 | |||
| 455 | 4 | 1; | |