From 9c04f01991930b1c5121fbb41d74f379cb42462c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Forst=C3=A9n?= Date: Mon, 24 Jun 2013 22:01:40 +0200 Subject: [PATCH] rewrite AlmostEqualUlps() to avoid compiler warnings concerning `strict-aliasing' --- src/maths/misc/equality.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/maths/misc/equality.c b/src/maths/misc/equality.c index 83c4ad3c5..f16380431 100644 --- a/src/maths/misc/equality.c +++ b/src/maths/misc/equality.c @@ -24,6 +24,11 @@ bool AlmostEqualUlps(double A, double B, int maxUlps) { int64_t aInt, bInt, intDiff; + union { + double d; + int64_t i; + } uA, uB; + if (A == B) return TRUE; @@ -34,12 +39,14 @@ bool AlmostEqualUlps(double A, double B, int maxUlps) /* default NAN won't compare as equal to anything. */ assert(maxUlps > 0 && maxUlps < 4 * 1024 * 1024); - aInt = *(int64_t*)&A; + uA.d = A; + aInt = uA.i; /* Make aInt lexicographically ordered as a twos-complement int */ if (aInt < 0) aInt = int64_min - aInt; - bInt = *(int64_t*)&B; + uB.d = B; + bInt = uB.i; /* Make bInt lexicographically ordered as a twos-complement int */ if (bInt < 0) bInt = int64_min - bInt;