Skip to content

mp_d2mp broken with gcc #3

Description

@rajamukherji

It looks like mp_d2mp generates an empty (zero) result (observed with gcc 15.2.1). My guess is an aliasing issue with the double * parameter. Using a union like below works fine, although their might be a better solution using frexp() or similar.

--- a/include/mp.h	2026-02-25 08:32:32.615644741 +0000
+++ b/include/mp.h	2026-02-25 08:25:58.773000000 +0000
@@ -649,7 +649,11 @@
 	   Reading it in as a uint64 makes this process
 	   endian-independent */
 
-	int_mant = *(uint64 *)(d);
+	union { uint64_t i; double d; } u;
+	u.d = *d;
+	int_mant = u.i;
+
+	//int_mant = *(uint64 *)(d);
 	exponent = ((int32)(int_mant >> 52) & 0x7ff) - 1023;
 	int_mant &= ~((uint64)(0xfff) << 52);
 	int_mant |= (uint64)(1) << 52;

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions