summaryrefslogtreecommitdiffstats
path: root/lib/msun/src/s_ceill.c
diff options
context:
space:
mode:
authorstefanf <stefanf@FreeBSD.org>2005-04-22 08:30:33 +0000
committerstefanf <stefanf@FreeBSD.org>2005-04-22 08:30:33 +0000
commit77782516eb51b13ce913730d6522843721cef913 (patch)
tree98d93b888d7f38495710281c3cc30696bf47dd2e /lib/msun/src/s_ceill.c
parent1d4ca8df02da84a302dfdd9feae99371773c0c6a (diff)
downloadFreeBSD-src-77782516eb51b13ce913730d6522843721cef913.zip
FreeBSD-src-77782516eb51b13ce913730d6522843721cef913.tar.gz
Fix raising the inexact exception (FE_INEXACT) if the result differs from the
argument. Noticed by: das
Diffstat (limited to 'lib/msun/src/s_ceill.c')
-rw-r--r--lib/msun/src/s_ceill.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/msun/src/s_ceill.c b/lib/msun/src/s_ceill.c
index 92f5033..1de973b 100644
--- a/lib/msun/src/s_ceill.c
+++ b/lib/msun/src/s_ceill.c
@@ -50,6 +50,8 @@ static char rcsid[] = "$FreeBSD$";
} while (0)
#endif
+static const long double huge = 1.0e300;
+
long double
ceill(long double x)
{
@@ -58,13 +60,14 @@ ceill(long double x)
if (e < MANH_SIZE - 1) {
if (e < 0) { /* raise inexact if x != 0 */
- if (u.bits.exp > 0 || (u.bits.manh | u.bits.manl) != 0)
- u.e = u.bits.sign ? 0.0 : 1.0;
+ if (huge + x > 0.0)
+ if (u.bits.exp > 0 ||
+ (u.bits.manh | u.bits.manl) != 0)
+ u.e = u.bits.sign ? 0.0 : 1.0;
} else {
uint64_t m = ((1llu << MANH_SIZE) - 1) >> (e + 1);
if (((u.bits.manh & m) | u.bits.manl) == 0)
return (x); /* x is integral */
- /* raise inexact flag */
if (!u.bits.sign) {
#ifdef LDBL_IMPLICIT_NBIT
if (e == 0)
@@ -73,14 +76,15 @@ ceill(long double x)
#endif
INC_MANH(u, 1llu << (MANH_SIZE - e - 1));
}
- u.bits.manh &= ~m;
- u.bits.manl = 0;
+ if (huge + x > 0.0) { /* raise inexact flag */
+ u.bits.manh &= ~m;
+ u.bits.manl = 0;
+ }
}
} else if (e < LDBL_MANT_DIG - 1) {
uint64_t m = (uint64_t)-1 >> (64 - LDBL_MANT_DIG + e + 1);
if ((u.bits.manl & m) == 0)
return (x); /* x is integral */
- /* raise inexact flag */
if (!u.bits.sign) {
if (e == MANH_SIZE - 1)
INC_MANH(u, 1);
@@ -91,7 +95,8 @@ ceill(long double x)
INC_MANH(u, 1);
}
}
- u.bits.manl &= ~m;
+ if (huge + x > 0.0) /* raise inexact flag */
+ u.bits.manl &= ~m;
}
return (u.e);
}
OpenPOWER on IntegriCloud