mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-01-21 05:49:19 +08:00
048ebea981
Rename s_nearbyint.c, s_fdim.c and s_scalbln.c to remove conflicts Remove functions that are not needed from above files Modify include paths Add includes missing in cygwin build Add missing types Create Makefiles Create header files to resolve dependencies between directories Modify some instances of unsigned long to uint64_t for 32 bit platforms Add HAVE_FPMATH_H
55 lines
1.2 KiB
C
55 lines
1.2 KiB
C
/*
|
|
* 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 <stdint.h>
|
|
|
|
#include "fpmath.h"
|
|
|
|
int
|
|
ilogbl(long double x)
|
|
{
|
|
union IEEEl2bits u;
|
|
uint64_t 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 = 1llu << (LDBL_MANL_SIZE - 1);
|
|
for (b = LDBL_MANH_SIZE; !(u.bits.manl & m); m >>= 1)
|
|
b++;
|
|
} else {
|
|
m = 1llu << (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);
|
|
}
|