From a84389f6bbf0cedd05ed9b5134331f68b2c88e42 Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Sun, 27 Aug 2023 23:52:47 +0200
Subject: [PATCH] libm: use union for infinity
---
src/libm/e_exp.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/src/libm/e_exp.c b/src/libm/e_exp.c
index 19f8ff7d55ed..a4c8cc89af0e 100644
--- a/src/libm/e_exp.c
+++ b/src/libm/e_exp.c
@@ -98,6 +98,13 @@ P3 = 6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */
P4 = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */
P5 = 4.13813679705723846039e-08; /* 0x3E663769, 0x72BEA4D0 */
+union {
+ Uint64 u64;
+ double d;
+} inf_union = {
+ 0x7ff0000000000000 /* Binary representation of a 64-bit infinite double (sign=0, exponent=2047, mantissa=0) */
+};
+
double __ieee754_exp(double x) /* default IEEE double exp */
{
double y;
@@ -123,6 +130,8 @@ double __ieee754_exp(double x) /* default IEEE double exp */
else return (xsb==0)? x:0.0; /* exp(+-inf)={inf,0} */
}
#if 1
+ if(x > o_threshold) return inf_union.d; /* overflow */
+ #elif 1
if(x > o_threshold) return huge*huge; /* overflow */
#else /* !!! FIXME: check this: "huge * huge" is a compiler warning, maybe they wanted +Inf? */
if(x > o_threshold) return INFINITY; /* overflow */