diff options
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 eaaae660..b50d61c2 100644 --- a/builtins/integers.c +++ b/builtins/integers.c @@ -36,6 +36,14 @@ public Int_t Int$from_num(double n) return Int$from_mpz(result); } +public double Int$as_num(Int_t i) +{ + if (__builtin_expect(i.small & 1, 1)) + return (double)(i.small >> 2); + + return mpz_get_d(*i.big); +} + public CORD Int$as_text(const Int_t *i, bool colorize, const TypeInfo *type) { (void)type; if (!i) return "Int"; diff --git a/builtins/integers.h b/builtins/integers.h index 33df2f89..218d8d23 100644 --- a/builtins/integers.h +++ b/builtins/integers.h @@ -79,6 +79,7 @@ Int_t Int$abs(Int_t x); #define Int$as_i64(i) (((i).small & 1) ? (int64_t)((i).small >> 2) : mpz_get_si(*(i).big)) Int_t Int$from_i64(int64_t i); Int_t Int$from_num(double n); +double Int$as_num(Int_t i); #define I(i) ((int64_t)(i) == (int32_t)(i) ? ((Int_t){.small=((uint64_t)(i)<<2)|1}) : Int$from_i64(i)) Int_t Int$plus(Int_t x, Int_t y); |
