]> git.ipfire.org Git - thirdparty/gcc.git/blame - libquadmath/math/ilogbq.c
Update most of libquadmath/math/ from glibc, automate update (PR libquadmath/68686).
[thirdparty/gcc.git] / libquadmath / math / ilogbq.c
CommitLineData
e409716d 1/* s_ilogbl.c -- long double version of s_ilogb.c.
e7b8ec29 2 * Conversion to IEEE quad long double by Jakub Jelinek, jj@ultra.linux.cz.
3 */
4
5/*
6 * ====================================================
7 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8 *
9 * Developed at SunPro, a Sun Microsystems, Inc. business.
10 * Permission to use, copy, modify, and distribute this
11 * software is freely granted, provided that this notice
12 * is preserved.
13 * ====================================================
14 */
15
16#if defined(LIBM_SCCS) && !defined(lint)
17static char rcsid[] = "$NetBSD: $";
18#endif
19
e409716d 20/* ilogbl(long double x)
e7b8ec29 21 * return the binary exponent of non-zero x
22 * ilogbl(0) = FP_ILOGB0
23 * ilogbl(NaN) = FP_ILOGBNAN (no signal is raised)
24 * ilogbl(+-Inf) = INT_MAX (no signal is raised)
25 */
26
e7b8ec29 27#include <math.h>
28#include "quadmath-imp.h"
e7b8ec29 29#ifndef FP_ILOGB0
30# define FP_ILOGB0 INT_MIN
31#endif
32#ifndef FP_ILOGBNAN
33# define FP_ILOGBNAN INT_MAX
34#endif
35
e409716d 36int ilogbq (__float128 x)
e7b8ec29 37{
38 int64_t hx,lx;
39 int ix;
40
41 GET_FLT128_WORDS64(hx,lx,x);
42 hx &= 0x7fffffffffffffffLL;
43 if(hx <= 0x0001000000000000LL) {
44 if((hx|lx)==0)
e409716d 45 { errno = EDOM; feraiseexcept (FE_INVALID); return FP_ILOGB0; } /* ilogbl(0) = FP_ILOGB0 */
e7b8ec29 46 else /* subnormal x */
47 if(hx==0) {
48 for (ix = -16431; lx>0; lx<<=1) ix -=1;
49 } else {
50 for (ix = -16382, hx<<=15; hx>0; hx<<=1) ix -=1;
51 }
52 return ix;
53 }
54 else if (hx<0x7fff000000000000LL) return (hx>>48)-0x3fff;
55 else if (FP_ILOGBNAN != INT_MAX) {
56 /* ISO C99 requires ilogbl(+-Inf) == INT_MAX. */
57 if (((hx^0x7fff000000000000LL)|lx) == 0)
e409716d 58 { errno = EDOM; feraiseexcept (FE_INVALID); return INT_MAX; }
e7b8ec29 59 }
e409716d 60 { errno = EDOM; feraiseexcept (FE_INVALID); return FP_ILOGBNAN; }
e7b8ec29 61}