aboutsummaryrefslogtreecommitdiff
path: root/src/mytype.h
diff options
context:
space:
mode:
authormirenn <me@mirenn.dev>2026-03-12 16:36:27 +0100
committermirenn <me@mirenn.dev>2026-04-14 09:44:28 +0200
commit6bb1a9b95b09663436c2fe30a8e2185a3f741af1 (patch)
tree5546f4c44b3e9ca09776dae0078db25af229247b /src/mytype.h
parenta8d572933d3a29e73bbbe20bc49e1fe988e55cfa (diff)
downloadinpla-6bb1a9b95b09663436c2fe30a8e2185a3f741af1.tar.gz
inpla-6bb1a9b95b09663436c2fe30a8e2185a3f741af1.zip
float support
Diffstat (limited to 'src/mytype.h')
-rw-r--r--src/mytype.h16
1 files changed, 14 insertions, 2 deletions
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)