From 2bb4cdbe9c8d091c1f384f1cd21e8ecd02db209e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Min=C3=A9?= Date: Tue, 28 Mar 2023 09:28:13 +0200 Subject: [PATCH] fix 64-bit bounds for convertion from double --- caml_z.c | 8 +++----- caml_z_tommath.c | 8 +++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/caml_z.c b/caml_z.c index 17e5dde..6816de9 100644 --- a/caml_z.c +++ b/caml_z.c @@ -160,12 +160,10 @@ extern "C" { #endif #define Z_FITS_INT(v) ((v) >= Z_MIN_INT && (v) <= Z_MAX_INT) -/* Z_MAX_INT may not be representable exactly as a double => we use a - lower approximation to be safe - */ +/* greatest/smallest double that can fit in an int */ #ifdef ARCH_SIXTYFOUR -#define Z_MAX_INT_FL 0x3ffffffffffff000 -#define Z_MIN_INT_FL (-Z_MAX_INT_FL) +#define Z_MAX_INT_FL 0x3ffffffffffffe00 +#define Z_MIN_INT_FL (-0x4000000000000000) #else #define Z_MAX_INT_FL Z_MAX_INT #define Z_MIN_INT_FL Z_MIN_INT diff --git a/caml_z_tommath.c b/caml_z_tommath.c index b8a9f38..7fbd56a 100644 --- a/caml_z_tommath.c +++ b/caml_z_tommath.c @@ -86,12 +86,10 @@ static mp_int z_max_intnat, z_min_intnat; static mp_int z_max_int32, z_min_int32; static mp_int z_max_int64, z_min_int64; -/* Z_MAX_INT may not be representable exactly as a double => we use a - lower approximation to be safe - */ +/* greatest/smallest double that can fit in an int */ #ifdef ARCH_SIXTYFOUR -#define Z_MAX_INT_FL 0x3ffffffffffff000 -#define Z_MIN_INT_FL (-Z_MAX_INT_FL) +#define Z_MAX_INT_FL 0x3ffffffffffffe00 +#define Z_MIN_INT_FL (-0x4000000000000000) #else #define Z_MAX_INT_FL Z_MAX_INT #define Z_MIN_INT_FL Z_MIN_INT