diff options
author | Jennifer Averett <jennifer.averett@oarcorp.com> | 2023-05-05 21:39:16 +0300 |
---|---|---|
committer | Joel Sherrill <joel@rtems.org> | 2023-05-16 17:05:36 +0300 |
commit | c630a6a837fd581d741fb94602aed6a4a5ed9bf4 (patch) | |
tree | be4cb97e5ba955b52a52b36e2c626d3b7c525f51 /newlib/libm/ld/s_ilogbl.c | |
parent | 41fdb869f9984ca2f8600aaa980b4ed2eae2e980 (diff) |
newlib: Add FreeBSD files for non LDBL_EQ_DBL support
FreeBSD files to add long double support for i386,
aarch64 and x86_64.
Diffstat (limited to 'newlib/libm/ld/s_ilogbl.c')
-rw-r--r-- | newlib/libm/ld/s_ilogbl.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/newlib/libm/ld/s_ilogbl.c b/newlib/libm/ld/s_ilogbl.c new file mode 100644 index 000000000..3211f4409 --- /dev/null +++ b/newlib/libm/ld/s_ilogbl.c @@ -0,0 +1,53 @@ +/* + * From: @(#)s_ilogb.c 5.1 93/09/24 + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <float.h> +#include <limits.h> +#include <math.h> + +#include "fpmath.h" + +int +ilogbl(long double x) +{ + union IEEEl2bits u; + unsigned long m; + int b; + + u.e = x; + if (u.bits.exp == 0) { + if ((u.bits.manl | u.bits.manh) == 0) + return (FP_ILOGB0); + /* denormalized */ + if (u.bits.manh == 0) { + m = 1lu << (LDBL_MANL_SIZE - 1); + for (b = LDBL_MANH_SIZE; !(u.bits.manl & m); m >>= 1) + b++; + } else { + m = 1lu << (LDBL_MANH_SIZE - 1); + for (b = 0; !(u.bits.manh & m); m >>= 1) + b++; + } +#ifdef LDBL_IMPLICIT_NBIT + b++; +#endif + return (LDBL_MIN_EXP - b - 1); + } else if (u.bits.exp < (LDBL_MAX_EXP << 1) - 1) + return (u.bits.exp - LDBL_MAX_EXP + 1); + else if (u.bits.manl != 0 || u.bits.manh != 0) + return (FP_ILOGBNAN); + else + return (INT_MAX); +} |