Add Int:sqrt()
This commit is contained in:
parent
e0223a4c20
commit
e56fd1aa94
@ -302,6 +302,14 @@ public Int_t Int$power(Int_t base, Int_t exponent)
|
||||
return Int$from_mpz(result);
|
||||
}
|
||||
|
||||
public Int_t Int$sqrt(Int_t i)
|
||||
{
|
||||
mpz_t result;
|
||||
mpz_init_set_int(result, i);
|
||||
mpz_sqrt(result, result);
|
||||
return Int$from_mpz(result);
|
||||
}
|
||||
|
||||
public Int_t Int$random(Int_t min, Int_t max) {
|
||||
int32_t cmp = Int$compare(&min, &max, &$Int);
|
||||
if (cmp > 0)
|
||||
|
@ -60,6 +60,7 @@ Range_t Int$to(Int_t from, Int_t to);
|
||||
Int_t Int$from_text(CORD text);
|
||||
Int_t Int$abs(Int_t x);
|
||||
Int_t Int$power(Int_t base, Int_t exponent);
|
||||
Int_t Int$sqrt(Int_t i);
|
||||
|
||||
#define BIGGEST_SMALL_INT ((1<<29)-1)
|
||||
|
||||
|
@ -107,6 +107,7 @@ env_t *new_compilation_unit(CORD *libname)
|
||||
{"negative", "Int$negative", "func(x:Int)->Int"},
|
||||
{"negated", "Int$negated", "func(x:Int)->Int"},
|
||||
{"abs", "Int$abs", "func(x:Int)->Int"},
|
||||
{"sqrt", "Int$sqrt", "func(x:Int)->Int"},
|
||||
{"power", "Int$power", "func(base:Int,exponent:Int)->Int"},
|
||||
)},
|
||||
{"Int64", Type(IntType, .bits=64), "Int64_t", "$Int64", TypedArray(ns_entry_t,
|
||||
|
Loading…
Reference in New Issue
Block a user