ReactOS 0.4.16-dev-106-g10b08aa
ldexp.c File Reference
#include "libm.h"
#include "libm_util.h"
#include "libm_new.h"
Include dependency graph for ldexp.c:

Go to the source code of this file.

Macros

#define FN_PROTOTYPE_REF   FN_PROTOTYPE
 
#define __amd_handle_error   _handle_error
 
#define __amd_ldexp   OP_LDEXP
 

Functions

double FN_PROTOTYPE_REF() ldexp (double x, int n)
 

Macro Definition Documentation

◆ __amd_handle_error

#define __amd_handle_error   _handle_error

Definition at line 33 of file ldexp.c.

◆ __amd_ldexp

#define __amd_ldexp   OP_LDEXP

Definition at line 34 of file ldexp.c.

◆ FN_PROTOTYPE_REF

#define FN_PROTOTYPE_REF   FN_PROTOTYPE

Definition at line 32 of file ldexp.c.

Function Documentation

◆ ldexp()

double FN_PROTOTYPE_REF() ldexp ( double  x,
int  n 
)

Definition at line 40 of file ldexp.c.

41{
42 UT64 val,val_x;
43 unsigned int sign;
44 int exponent;
45 val.f64 = x;
46 val_x.f64 = x;
47 sign = val.u32[1] & 0x80000000;
48 val.u32[1] = val.u32[1] & 0x7fffffff; /* remove the sign bit */
49
50 if (val.u64 > 0x7ff0000000000000) /* x is NaN */
51 #ifdef WINDOWS
52 return __amd_handle_error("ldexp", __amd_ldexp, val_x.u64|0x0008000000000000, _DOMAIN, 0, EDOM, x, n, 2);
53 #else
54 {
55 if(!(val.u64 & 0x0008000000000000))// x is snan
56 return __amd_handle_error("ldexp", __amd_ldexp, val_x.u64|0x0008000000000000, _DOMAIN, AMD_F_INVALID, EDOM, x, n, 2);
57 else
58 return x;
59 }
60 #endif
61
62 if(val.u64 == 0x7ff0000000000000)/* x = +-inf*/
63 return x;
64
65 if((val.u64 == 0x0000000000000000) || (n==0))
66 return x; /* x= +-0 or n= 0*/
67
68 exponent = val.u32[1] >> 20; /* get the exponent */
69
70 if(exponent == 0)/*x is denormal*/
71 {
72 val.f64 = val.f64 * VAL_2PMULTIPLIER_DP;/*multiply by 2^53 to bring it to the normal range*/
73 exponent = val.u32[1] >> 20; /* get the exponent */
74 exponent = exponent + n - MULTIPLIER_DP;
75 if(exponent < -MULTIPLIER_DP)/*underflow*/
76 {
77 val.u32[1] = sign | 0x00000000;
78 val.u32[0] = 0x00000000;
80 }
81 if(exponent > 2046)/*overflow*/
82 {
83 val.u32[1] = sign | 0x7ff00000;
84 val.u32[0] = 0x00000000;
85 return __amd_handle_error("ldexp", __amd_ldexp, val.u64, _OVERFLOW, AMD_F_INEXACT|AMD_F_OVERFLOW, ERANGE ,x, (double)n, 2);
86 }
87
88 exponent += MULTIPLIER_DP;
89 val.u32[1] = sign | (exponent << 20) | (val.u32[1] & 0x000fffff);
90 val.f64 = val.f64 * VAL_2PMMULTIPLIER_DP;
91 return val.f64;
92 }
93
94 exponent += n;
95
96 if(exponent < -MULTIPLIER_DP)/*underflow*/
97 {
98 val.u32[1] = sign | 0x00000000;
99 val.u32[0] = 0x00000000;
100 return __amd_handle_error("ldexp", __amd_ldexp, val.u64, _UNDERFLOW, AMD_F_INEXACT|AMD_F_UNDERFLOW, ERANGE, x, (double)n, 2);
101 }
102
103 if(exponent < 1)/*x is normal but output is debnormal*/
104 {
105 exponent += MULTIPLIER_DP;
106 val.u32[1] = sign | (exponent << 20) | (val.u32[1] & 0x000fffff);
107 val.f64 = val.f64 * VAL_2PMMULTIPLIER_DP;
108 return val.f64;
109 }
110
111 if(exponent > 2046)/*overflow*/
112 {
113 val.u32[1] = sign | 0x7ff00000;
114 val.u32[0] = 0x00000000;
115 return __amd_handle_error("ldexp", __amd_ldexp, val.u64, _OVERFLOW, AMD_F_INEXACT|AMD_F_OVERFLOW, ERANGE ,x, (double)n, 2);
116 }
117
118 val.u32[1] = sign | (exponent << 20) | (val.u32[1] & 0x000fffff);
119 return val.f64;
120}
#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_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
#define __amd_ldexp
Definition: ldexp.c:34
#define __amd_handle_error
Definition: ldexp.c:33
static const double VAL_2PMULTIPLIER_DP
Definition: libm_util.h:38
#define MULTIPLIER_DP
Definition: libm_util.h:36
static const double VAL_2PMMULTIPLIER_DP
Definition: libm_util.h:39
#define sign(x)
Definition: mapdesc.cc:613
Definition: libm_new.h:47
F64 f64
Definition: libm_new.h:48
U64 u64
Definition: libm_new.h:49