diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2026-01-11 14:45:08 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2026-01-11 14:45:08 -0500 |
| commit | e4b29d85a8508402e148d62cceaa97a4388ac209 (patch) | |
| tree | d1d8462f853e8edbef8d3137ec7f6201329589cf /src/stdlib/reals.h | |
| parent | 71806bffc5517d8928271e28d9cd1d9f519a7d25 (diff) | |
Rework reals
Diffstat (limited to 'src/stdlib/reals.h')
| -rw-r--r-- | src/stdlib/reals.h | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/src/stdlib/reals.h b/src/stdlib/reals.h index 8750fdbb..ff880de7 100644 --- a/src/stdlib/reals.h +++ b/src/stdlib/reals.h @@ -4,26 +4,39 @@ #include "datatypes.h" #include "types.h" -#define NONE_REAL ((Real_t)NULL) +// NaN-boxing scheme: use quiet NaN space for pointers +// IEEE 754: NaN = exponent all 1s, mantissa non-zero +// Quiet NaN: sign bit can be anything, bit 51 = 1 +#define QNAN_MASK 0x7FF8000000000000ULL +#define TAG_MASK 0x0007000000000000ULL +#define PTR_MASK 0x0000FFFFFFFFFFFFULL -Int_t Real$compute(Real_t r, int64_t decimals); -Text_t Real$value_as_text(Real_t x, int64_t decimals); +#define REAL_TAG_BIGINT 0x0001000000000000ULL +#define REAL_TAG_RATIONAL 0x0002000000000000ULL +#define REAL_TAG_CONSTRUCTIVE 0x0003000000000000ULL +#define REAL_TAG_SYMBOLIC 0x0004000000000000ULL +#define REAL_TAG_NONE 0x0005000000000000ULL + +#define NONE_REAL ((Real_t){.u64 = QNAN_MASK | REAL_TAG_NONE}) + +Text_t Real$value_as_text(Real_t x); OptionalReal_t Real$parse(Text_t text, Text_t *remainder); Real_t Real$from_text(Text_t text); Real_t Real$from_float64(double n); Real_t Real$from_int(Int_t i); -double Real$as_float64(Real_t x); -Int_t Real$as_int(Real_t x); +double Real$as_float64(Real_t n, bool truncate); +Int_t Real$as_int(Real_t x, bool truncate); Real_t Real$negative(Real_t x); -Real_t Real$sqrt(Real_t x); Real_t Real$plus(Real_t x, Real_t y); Real_t Real$minus(Real_t x, Real_t y); Real_t Real$times(Real_t x, Real_t y); Real_t Real$divided_by(Real_t x, Real_t y); -Real_t Real$left_shifted(Real_t x, Int_t amount); -Real_t Real$right_shifted(Real_t x, Int_t amount); +Real_t Real$power(Real_t base, Real_t exp); +Real_t Real$sqrt(Real_t x); + +int Real$test(); extern const TypeInfo_t Real$info; |
