2011-08-12 21:01:25 +02:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
* ====================================================
|
|
|
|
*/
|
|
|
|
|
2012-04-09 02:03:36 +02:00
|
|
|
#include "cdefs-compat.h"
|
2011-12-15 07:16:26 +01:00
|
|
|
//__FBSDID("$FreeBSD: src/lib/msun/src/s_ilogbl.c,v 1.2 2008/02/22 02:30:35 das Exp $");
|
2011-08-12 21:01:25 +02:00
|
|
|
|
|
|
|
#include <float.h>
|
|
|
|
#include <limits.h>
|
2015-01-11 23:34:27 +01:00
|
|
|
#include <openlibm_math.h>
|
|
|
|
|
2011-12-16 06:30:31 +01:00
|
|
|
#include "fpmath.h"
|
2015-01-11 23:34:27 +01:00
|
|
|
#include "math_private.h"
|
2011-08-12 21:01:25 +02:00
|
|
|
|
2016-03-14 02:07:55 +01:00
|
|
|
OLM_DLLEXPORT int
|
2011-08-12 21:01:25 +02:00
|
|
|
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);
|
|
|
|
}
|