ReactOS 0.4.16-dev-303-g11d5cb8
cabsf.c File Reference
#include "libm.h"
Include dependency graph for cabsf.c:

Go to the source code of this file.

Functions

float _hypotf (float, float)
 
float _cabsf (COMPLEX z)
 

Function Documentation

◆ _cabsf()

float _cabsf ( COMPLEX  z)

Definition at line 30 of file cabsf.c.

31{
32 /* Returns the absolute value of a complex number z
33 with real part a and complex part b. */
34return _hypotf((float)z.x, (float)z.y);
35}
float _hypotf(float, float)
Definition: hypotf.c:45
GLdouble GLdouble z
Definition: glext.h:5874

◆ _hypotf()

float _hypotf ( float  x,
float  y 
)

Definition at line 45 of file hypotf.c.

46{
47 /* Returns sqrt(x*x + y*y) with no overflow or underflow unless
48 the result warrants it */
49
50 /* Do intermediate computations in double precision
51 and use sqrt instruction from chip if available. */
52 double dx = x, dy = y, dr, retval;
53
54 /* The largest finite float, stored as a double */
55 const double large = 3.40282346638528859812e+38; /* 0x47efffffe0000000 */
56
57
58 unsigned long long ux, uy, avx, avy;
59
61 avx &= ~SIGNBIT_DP64;
62 GET_BITS_DP64(y, avy);
63 avy &= ~SIGNBIT_DP64;
64 ux = (avx >> EXPSHIFTBITS_DP64);
65 uy = (avy >> EXPSHIFTBITS_DP64);
66
67 if (ux == BIASEDEMAX_DP64 + 1 || uy == BIASEDEMAX_DP64 + 1)
68 {
69 retval = x*x + y*y;
70 /* One or both of the arguments are NaN or infinity. The
71 result will also be NaN or infinity. */
72 if (((ux == BIASEDEMAX_DP64 + 1) && !(avx & MANTBITS_DP64)) ||
73 ((uy == BIASEDEMAX_DP64 + 1) && !(avy & MANTBITS_DP64)))
74 /* x or y is infinity. ISO C99 defines that we must
75 return +infinity, even if the other argument is NaN.
76 Note that the computation of x*x + y*y above will already
77 have raised invalid if either x or y is a signalling NaN. */
78 return infinityf_with_flags(0);
79 else
80 /* One or both of x or y is NaN, and neither is infinity.
81 Raise invalid if it's a signalling NaN */
82 return (float)retval;
83 }
84
85 dr = (dx*dx + dy*dy);
86
87#if USE_SOFTWARE_SQRT
88 retval = sqrtf_amd_inline(r);
89#else
90 /* VC++ intrinsic call */
92#endif
93
94 if (retval > large)
95 return _handle_errorf("_hypotf", OP_HYPOT, PINFBITPATT_SP32, _OVERFLOW,
97 else
98 return (float)retval;
99}
float __cdecl _handle_errorf(char *fname, int opcode, unsigned long long value, int type, int flags, int error, float arg1, float arg2, int nargs)
Definition: _handle_error.c:56
#define ERANGE
Definition: acclib.h:92
__m128d _mm_setzero_pd(void)
Definition: emmintrin.h:1055
__m128d _mm_sqrt_sd(__m128d a, __m128d b)
Definition: emmintrin.h:618
__m128d _mm_load_sd(double const *dp)
Definition: emmintrin.h:998
void _mm_store_sd(double *dp, __m128d a)
Definition: emmintrin.h:1066
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define _OVERFLOW
Definition: math.h:41
#define AMD_F_INEXACT
Definition: libm_new.h:82
#define AMD_F_OVERFLOW
Definition: libm_new.h:83
#define EXPSHIFTBITS_DP64
Definition: libm_util.h:56
#define GET_BITS_DP64(x, ux)
Definition: libm_util.h:118
#define BIASEDEMAX_DP64
Definition: libm_util.h:59
#define PINFBITPATT_SP32
Definition: libm_util.h:77
#define MANTBITS_DP64
Definition: libm_util.h:46
GLint dy
Definition: linetemp.h:97
GLint dx
Definition: linetemp.h:97
@ avx
Definition: optimize.h:112

Referenced by _cabsf().