3 A_HIDDEN a_f64
a_f64_sq(a_f64 x
, a_f64
*o
);
4 a_f64
a_f64_sq(a_f64 x
, a_f64
*o
)
7 #if defined(_MSC_VER) && (_MSC_VER < 1914)
12 } u
= {A_U64_C(0x41A0000000000000)};
15 #define U A_F64_C(0x1P27)
22 *o
= xh
* xh
- x
+ 2 * xh
* xl
+ xl
* xl
;
28 a_f32
a_f32_hypot(a_f32 x
, a_f32 y
)
32 #if defined(_MSC_VER) && (_MSC_VER < 1914)
37 } max
= {A_U32_C(0x6C800000)},
38 min
= {A_U32_C(0x12800000)};
42 #define MAX A_F32_C(0x1P+90)
43 #define MIN A_F32_C(0x1P-90)
54 ux
.u
&= A_U32_C(~0) >> 1;
55 uy
.u
&= A_U32_C(~0) >> 1;
65 if (uy
.u
== 0xFF << 23) { return y
; }
66 if (ux
.u
>= 0xFF << 23 || uy
.u
== 0 || ux
.u
- uy
.u
>= 25 << 23) { return x
+ y
; }
69 if (ux
.u
>= (0x7F + 60) << 23)
75 else if (uy
.u
< (0x7F - 60) << 23)
81 return z
* a_f32_sqrt((a_f32
)((a_f64
)x
* (a_f64
)x
+ (a_f64
)y
* (a_f64
)y
));
87 a_f64
a_f64_hypot(a_f64 x
, a_f64 y
)
91 #if defined(_MSC_VER) && (_MSC_VER < 1914)
96 } max
= {A_U64_C(0x6BB0000000000000)},
97 min
= {A_U64_C(0x1430000000000000)};
101 #define MAX A_F64_C(0x1P+700)
102 #define MIN A_F64_C(0x1P-700)
110 a_f64 hx
, lx
, hy
, ly
, z
;
114 ux
.u
&= A_U64_C(~0) >> 1;
115 uy
.u
&= A_U64_C(~0) >> 1;
125 ex
= (unsigned int)(ux
.u
>> 52);
126 ey
= (unsigned int)(uy
.u
>> 52);
127 /* hypot(inf,nan) == inf */
128 if (ey
== 0x7FF) { return y
; }
129 if (ex
== 0x7FF || uy
.u
== 0) { return x
; }
130 if (ex
- ey
> 64) { return x
+ y
; }
133 if (ex
> 0x3FF + 510)
139 else if (ey
< 0x3FF - 450)
145 hx
= a_f64_sq(x
, &lx
);
146 hy
= a_f64_sq(y
, &ly
);
147 return z
* a_f64_sqrt(ly
+ lx
+ hy
+ hx
);
152 a_f32
a_f32_rsqrt(a_f32 x
)
155 return 1 / a_f32_sqrt(x
);
165 a_f32 xh
= A_F32_C(0.5) * x
;
166 u
.u
= A_U32_C(0x5F375A86) - (u
.u
>> 1);
167 u
.x
*= A_F32_C(1.5) - u
.x
* u
.x
* xh
;
168 u
.x
*= A_F32_C(1.5) - u
.x
* u
.x
* xh
;
182 a_f64
a_f64_rsqrt(a_f64 x
)
185 return 1 / a_f64_sqrt(x
);
195 a_f64 xh
= A_F64_C(0.5) * x
;
196 u
.u
= A_U64_C(0x5FE6EC85E7DE30DA) - (u
.u
>> 1);
197 u
.x
*= A_F64_C(1.5) - u
.x
* u
.x
* xh
;
198 u
.x
*= A_F64_C(1.5) - u
.x
* u
.x
* xh
;
212 a_u16
a_u32_sqrt(a_u32 x
)
214 #if 0 /* Newton's method */
216 if (x
<= 1) { return (a_u16
)x
; }
220 x1
= (x0
+ x
/ x0
) >> 1;
223 #else /* Digit-by-digit */
224 a_u32 a
, b
= 1, y
= 0;
225 for (b
<<= sizeof(b
) * 8 - 2; b
> x
; b
>>= 2) {}
240 a_u32
a_u64_sqrt(a_u64 x
)
242 #if 0 /* Newton's method */
244 if (x
<= 1) { return (a_u32
)x
; }
248 x1
= (x0
+ x
/ x0
) >> 1;
251 #else /* Digit-by-digit */
252 a_u64 a
, b
= 1, y
= 0;
253 for (b
<<= sizeof(b
) * 8 - 2; b
> x
; b
>>= 2) {}
269 a_float
a_float_log1p(a_float x
) { return a_float_log(x
+ 1); }
272 a_float
a_float_hypot(a_float x
, a_float y
)
274 #if A_FLOAT_TYPE + 0 == A_FLOAT_SINGLE
275 return a_f32_hypot(x
, y
);
276 #elif A_FLOAT_TYPE + 0 == A_FLOAT_DOUBLE
277 return a_f64_hypot(x
, y
);
278 #elif A_FLOAT_TYPE + 0 == A_FLOAT_EXTEND
279 return a_float_sqrt(x
* x
+ y
* y
);
280 #endif /* A_FLOAT_TYPE */
284 a_float
a_float_atan2(a_float x
, a_float y
)
286 if (x
> 0) { return a_float_atan(y
/ x
); }
289 if (y
>= 0) { return a_float_atan(y
/ x
) + A_FLOAT_PI
; }
290 return a_float_atan(y
/ x
) - A_FLOAT_PI
;
292 if (y
> 0) { return +A_FLOAT_PI
; }
293 if (y
< 0) { return -A_FLOAT_PI
; }