ReactOS 0.4.15-dev-7906-g1b85a5f
hypot.c File Reference
#include <precomp.h>
Include dependency graph for hypot.c:

Go to the source code of this file.

Macros

#define __SQRT_DBL_MAX   1.3e+154
 
#define __SQRT_DBL_MIN   2.3e-162
 

Functions

double _hypot (double x, double y)
 

Macro Definition Documentation

◆ __SQRT_DBL_MAX

#define __SQRT_DBL_MAX   1.3e+154

Definition at line 27 of file hypot.c.

◆ __SQRT_DBL_MIN

#define __SQRT_DBL_MIN   2.3e-162

Definition at line 28 of file hypot.c.

Function Documentation

◆ _hypot()

double _hypot ( double  x,
double  y 
)

Definition at line 34 of file hypot.c.

35{
36 double abig = fabs(x), asmall = fabs(y);
37 double ratio;
38
39 /* Make abig = max(|x|, |y|), asmall = min(|x|, |y|). */
40 if (abig < asmall)
41 {
42 double temp = abig;
43
44 abig = asmall;
45 asmall = temp;
46 }
47
48 /* Trivial case. */
49 if (asmall == 0.)
50 return abig;
51
52 /* Scale the numbers as much as possible by using its ratio.
53 For example, if both ABIG and ASMALL are VERY small, then
54 X^2 + Y^2 might be VERY inaccurate due to loss of
55 significant digits. Dividing ASMALL by ABIG scales them
56 to a certain degree, so that accuracy is better. */
57
58 if ((ratio = asmall / abig) > __SQRT_DBL_MIN && abig < __SQRT_DBL_MAX)
59 return abig * sqrt(1.0 + ratio*ratio);
60 else
61 {
62 /* Slower but safer algorithm due to Moler and Morrison. Never
63 produces any intermediate result greater than roughly the
64 larger of X and Y. Should converge to machine-precision
65 accuracy in 3 iterations. */
66
67 double r = ratio*ratio, t, s, p = abig, q = asmall;
68
69 do {
70 t = 4. + r;
71 if (t == 4.)
72 break;
73 s = r / t;
74 p += 2. * s * p;
75 q *= s;
76 r = (q / p) * (q / p);
77 } while (1);
78
79 return p;
80 }
81}
_STLP_DECLSPEC complex< float > _STLP_CALL sqrt(const complex< float > &)
Definition: complex.cpp:188
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLdouble s
Definition: gl.h:2039
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLdouble GLdouble t
Definition: gl.h:2047
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
GLfloat GLfloat p
Definition: glext.h:8902
#define __SQRT_DBL_MAX
Definition: hypot.c:27
#define __SQRT_DBL_MIN
Definition: hypot.c:28
_Check_return_ _CRT_JIT_INTRINSIC double __cdecl fabs(_In_ double x)
Definition: fabs.c:17
static calc_node_t temp
Definition: rpn_ieee.c:38