ReactOS 0.4.16-dev-250-g3ecd236
ldexpf.c File Reference
#include "libm.h"
#include "libm_util.h"
#include "libm_new.h"
Include dependency graph for ldexpf.c:

Go to the source code of this file.

Macros

#define FN_PROTOTYPE_REF   FN_PROTOTYPE
 
#define __amd_handle_errorf   _handle_errorf
 
#define __amd_ldexp   OP_LDEXP
 

Functions

float FN_PROTOTYPE_REF() ldexpf (float x, int n)
 

Macro Definition Documentation

◆ __amd_handle_errorf

#define __amd_handle_errorf   _handle_errorf

Definition at line 33 of file ldexpf.c.

◆ __amd_ldexp

#define __amd_ldexp   OP_LDEXP

Definition at line 34 of file ldexpf.c.

◆ FN_PROTOTYPE_REF

#define FN_PROTOTYPE_REF   FN_PROTOTYPE

Definition at line 32 of file ldexpf.c.

Function Documentation

◆ ldexpf()

float FN_PROTOTYPE_REF() ldexpf ( float  x,
int  n 
)

Definition at line 40 of file ldexpf.c.

41{
42 UT32 val,val_x;
43 unsigned int sign;
44 int exponent;
45 val.f32 = x;
46 val_x.f32 = x;
47 sign = val.u32 & 0x80000000;
48 val.u32 = val.u32 & 0x7fffffff;/* remove the sign bit */
49
50 if(val.u32 > 0x7f800000)/* x= nan */
51 #ifdef WINDOWS
52 return __amd_handle_errorf("ldexpf", __amd_ldexp, val_x.u32|0x00400000, _DOMAIN, 0, EDOM, x, (float)n, 2);
53 #else
54 {
55 if(!(val.u32 & 0x00400000)) //x is snan
56 return __amd_handle_errorf("ldexpf", __amd_ldexp, val_x.u32|0x00400000, _DOMAIN, AMD_F_INVALID, EDOM, x, (float)n, 2);
57 else
58 return x;
59 }
60 #endif
61
62 if(val.u32 == 0x7f800000)/* x = +-inf*/
63 return x;
64
65 if((val.u32 == 0x00000000) || (n==0))/* x= +-0 or n= 0*/
66 return x;
67
68 exponent = val.u32 >> 23; /* get the exponent */
69
70 if(exponent == 0)/*x is denormal*/
71 {
72 val.f32 = val.f32 * VAL_2PMULTIPLIER_SP;/*multiply by 2^24 to bring it to the normal range*/
73 exponent = (val.u32 >> 23); /* get the exponent */
74 exponent = exponent + n - MULTIPLIER_SP;
75 if(exponent < -MULTIPLIER_SP)/*underflow*/
76 {
77 val.u32 = sign | 0x00000000;
79 }
80 if(exponent > 254)/*overflow*/
81 {
82 val.u32 = sign | 0x7f800000;
84 }
85
86 exponent += MULTIPLIER_SP;
87 val.u32 = sign | (exponent << 23) | (val.u32 & 0x007fffff);
88 val.f32 = val.f32 * VAL_2PMMULTIPLIER_SP;
89 return val.f32;
90 }
91
92 exponent += n;
93
94 if(exponent < -MULTIPLIER_SP)/*underflow*/
95 {
96 val.u32 = sign | 0x00000000;
98 }
99
100 if(exponent < 1)/*x is normal but output is debnormal*/
101 {
102 exponent += MULTIPLIER_SP;
103 val.u32 = sign | (exponent << 23) | (val.u32 & 0x007fffff);
104 val.f32 = val.f32 * VAL_2PMMULTIPLIER_SP;
105 return val.f32;
106 }
107
108 if(exponent > 254)/*overflow*/
109 {
110 val.u32 = sign | 0x7f800000;
111 return __amd_handle_errorf("ldexpf", __amd_ldexp, val.u32, _OVERFLOW, AMD_F_INEXACT|AMD_F_OVERFLOW, ERANGE, x, (float)n, 2);
112 }
113
114 val.u32 = sign | (exponent << 23) | (val.u32 & 0x007fffff);/*x is normal and output is normal*/
115 return val.f32;
116}
#define ERANGE
Definition: acclib.h:92
#define EDOM
Definition: errno.h:39
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLdouble n
Definition: glext.h:7729
GLuint GLfloat * val
Definition: glext.h:7180
#define _DOMAIN
Definition: math.h:39
#define _UNDERFLOW
Definition: math.h:42
#define _OVERFLOW
Definition: math.h:41
#define __amd_ldexp
Definition: ldexpf.c:34
#define __amd_handle_errorf
Definition: ldexpf.c:33
#define AMD_F_INEXACT
Definition: libm_new.h:82
#define AMD_F_UNDERFLOW
Definition: libm_new.h:84
#define AMD_F_INVALID
Definition: libm_new.h:86
#define AMD_F_OVERFLOW
Definition: libm_new.h:83
static const float VAL_2PMULTIPLIER_SP
Definition: libm_util.h:40
static const float VAL_2PMMULTIPLIER_SP
Definition: libm_util.h:41
#define MULTIPLIER_SP
Definition: libm_util.h:35
#define sign(x)
Definition: mapdesc.cc:613
Definition: libm_new.h:41
F32 f32
Definition: libm_new.h:42
U32 u32
Definition: libm_new.h:43