From 6bb1a9b95b09663436c2fe30a8e2185a3f741af1 Mon Sep 17 00:00:00 2001 From: mirenn Date: Thu, 12 Mar 2026 16:36:27 +0100 Subject: float support --- src/mytype.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/mytype.h') diff --git a/src/mytype.h b/src/mytype.h index bdfbfee..a1e6e81 100644 --- a/src/mytype.h +++ b/src/mytype.h @@ -53,8 +53,20 @@ typedef struct EQList_tag { #define FIXNUM_FLAG 0x01 -#define INT2FIX(i) ((VALUE)(((long)(i) << 1) | FIXNUM_FLAG)) -#define FIX2INT(i) ((long)(i) >> 1) + +static inline VALUE FLOAT2FIX(double f) { + union { float f; unsigned int i; } u; + u.f = (float)f; + VALUE v = u.i; + return (v << 32) | FIXNUM_FLAG; +} + +static inline double FIX2FLOAT(VALUE v) { + union { float f; unsigned int i; } u; + u.i = (unsigned int)(v >> 32); + return (double)u.f; +} + #define IS_FIXNUM(i) ((VALUE)(i) & FIXNUM_FLAG) -- cgit v1.2.3