From f67a15f38ed1e98df4e35e1cb8f4d6a3a146ae76 Mon Sep 17 00:00:00 2001 From: dwmalone Date: Tue, 13 Aug 2002 14:17:39 +0000 Subject: Use a union to access the words of a double as this is less likely to cause bugs when gcc is more aggressively optimising things. There are still problems with dtoa mentioned in the PR - maybe Dan could suggest a patch. PR: 40209 Submitted by: Dan Lukes Approved by: bde MFC after: 2 weeks --- lib/libc/stdlib/strtod.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/stdlib/strtod.c b/lib/libc/stdlib/strtod.c index eaa7ad0..9295583 100644 --- a/lib/libc/stdlib/strtod.c +++ b/lib/libc/stdlib/strtod.c @@ -222,12 +222,16 @@ extern "C" { Only one of IEEE_LITTLE_ENDIAN, IEEE_BIG_ENDIAN, VAX, or IBM should be defined. #endif +union doubleasulongs { + double x; + ULong w[2]; +}; #ifdef IEEE_LITTLE_ENDIAN -#define word0(x) ((ULong *)&x)[1] -#define word1(x) ((ULong *)&x)[0] +#define word0(x) (((union doubleasulongs *)&x)->w)[1] +#define word1(x) (((union doubleasulongs *)&x)->w)[0] #else -#define word0(x) ((ULong *)&x)[0] -#define word1(x) ((ULong *)&x)[1] +#define word0(x) (((union doubleasulongs *)&x)->w)[0] +#define word1(x) (((union doubleasulongs *)&x)->w)[1] #endif /* The following definition of Storeinc is appropriate for MIPS processors. -- cgit v1.1