this repo has no description
at fixPythonPipStalling 91 lines 1.5 kB view raw
1/* 2 * ilogb.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 "required_arithmetic.h" 16 17int ilogb( double x ) 18{ 19 union{ double d; uint64_t u;}u = {x}; 20 21 u.u &= 0x7fffffffffffffffULL; 22 int32_t exp = (int32_t) (u.u >> 52); 23 24 if( __builtin_expect( (uint32_t) exp - 1U >= 2046, 0 ) ) 25 { // +-0, +-denorm, +-inf, NaN 26 if( 0.0 == x ) 27 { 28 required_multiply_double( x, __builtin_inf() ); //set invalid 29 return FP_ILOGB0; 30 } 31 32 if( x != x ) 33 { 34 required_multiply_double( 0.0, __builtin_inf() ); //set invalid 35 return FP_ILOGBNAN; 36 } 37 38 if( u.u == 0x7ff0000000000000ULL ) 39 { 40 required_multiply_double( 0.0, x ); //set invalid 41 return INT_MAX; 42 } 43 44 u.u |= 0x3ff0000000000000ULL; 45 u.d -= 1.0; 46 exp = (int32_t) (u.u >> 52); 47 48 return exp - (1023+1022); 49 } 50 51 return exp - 1023; 52} 53 54#else 55 56int ilogb( double x ) 57{ 58 union{ double d; uint64_t u;}u = {x}; 59 60 u.u &= 0x7fffffffffffffffULL; 61 int32_t exp = (int32_t) (u.u >> 52); 62 63 if( __builtin_expect( (uint32_t) exp - 1U >= 2046, 0 ) ) 64 { // +-0, +-denorm, +-inf, NaN 65 if( 0.0 == x ) 66 { 67 return FP_ILOGB0; 68 } 69 70 if( x != x ) 71 { 72 return FP_ILOGBNAN; 73 } 74 75 if( u.u == 0x7ff0000000000000ULL ) 76 { 77 return INT_MAX; 78 } 79 80 u.u |= 0x3ff0000000000000ULL; 81 u.d -= 1.0; 82 exp = (int32_t) (u.u >> 52); 83 84 return exp - (1023+1022); 85 } 86 87 return exp - 1023; 88} 89 90#endif // ARMLIBM_SET_FLAGS 91