Skip to content

Commit

Permalink
fix 64-bit bounds for convertion from double
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinemine committed Mar 28, 2023
1 parent 6ce46a5 commit 2bb4cdb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
8 changes: 3 additions & 5 deletions caml_z.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions caml_z_tommath.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2bb4cdb

Please sign in to comment.