this repo has no description
1/*
2 * ilogbf.h
3 * cLibm
4 *
5 * Created by Ian Ollmann on 6/13/07.
6 * Copyright 2007 Apple Inc. All rights reserved.
7 *
8 */
9
10#include <math.h>
11#include <stdint.h>
12#include <limits.h>
13
14#ifdef ARMLIBM_SET_FLAGS
15#include <fenv.h>
16#include "required_arithmetic.h"
17#pragma STDC FENV_ACCESS ON
18
19int ilogbf( float x )
20{
21 union{ float f; uint32_t u;}u = {x};
22
23 u.u &= 0x7fffffff;
24 int32_t exp = u.u >> 23;
25
26 if( __builtin_expect( (uint32_t) exp - 1U >= 254, 0 ) )
27 { // +-0, +-denorm, +-inf, NaN
28 if( 0.0f == x )
29 {
30 required_multiply_float( x, __builtin_inff() ); //set invalid
31 return FP_ILOGB0;
32 }
33
34 if( x != x )
35 {
36 required_multiply_float( 0.0f, __builtin_inff() ); //set invalid
37 return FP_ILOGBNAN;
38 }
39
40 if( u.u == 0x7f800000 )
41 {
42 required_multiply_float( 0.0f, x ); //set invalid
43 return INT_MAX;
44 }
45
46 u.u |= 0x3f800000U;
47 u.f -= 1.0f;
48 exp = u.u >> 23;
49
50 return exp - (127+126);
51 }
52
53 return exp - 127;
54}
55
56#else
57
58int ilogbf( float x )
59{
60 union{ float f; uint32_t u;}u = {x};
61
62 u.u &= 0x7fffffff;
63 int32_t exp = u.u >> 23;
64
65 if( __builtin_expect( (uint32_t) exp - 1U >= 254, 0 ) )
66 { // +-0, +-denorm, +-inf, NaN
67 if( 0.0f == x )
68 {
69 return FP_ILOGB0;
70 }
71
72 if( x != x )
73 {
74 return FP_ILOGBNAN;
75 }
76
77 if( u.u == 0x7f800000 )
78 {
79 return INT_MAX;
80 }
81
82 u.u |= 0x3f800000U;
83 u.f -= 1.0f;
84 exp = u.u >> 23;
85
86 return exp - (127+126);
87 }
88
89 return exp - 127;
90}
91
92#endif // ARMLIBM_SET_FLAGS