diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-08-13 16:36:41 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-08-13 16:36:41 -0400 |
| commit | e56fd1aa94db77c6210c649c9cf8163678326355 (patch) | |
| tree | 9e487108faea515f34dd6e5a3664d1272f12f74d /builtins | |
| parent | e0223a4c201b42ca35c73bfad84477efc61f06b2 (diff) | |
Add Int:sqrt()
Diffstat (limited to 'builtins')
| -rw-r--r-- | builtins/integers.c | 8 | ||||
| -rw-r--r-- | builtins/integers.h | 1 |
2 files changed, 9 insertions, 0 deletions
diff --git a/builtins/integers.c b/builtins/integers.c index e55d2ab0..b7d96a90 100644 --- a/builtins/integers.c +++ b/builtins/integers.c @@ -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) diff --git a/builtins/integers.h b/builtins/integers.h index 8250e0dc..98b58b0f 100644 --- a/builtins/integers.h +++ b/builtins/integers.h @@ -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) |
