]>
git.proxmox.com Git - rustc.git/blob - vendor/compiler_builtins/libm/src/math/atan2f.rs
1 /* origin: FreeBSD /usr/src/lib/msun/src/e_atan2f.c */
3 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
6 * ====================================================
7 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
9 * Developed at SunPro, a Sun Microsystems, Inc. business.
10 * Permission to use, copy, modify, and distribute this
11 * software is freely granted, provided that this notice
13 * ====================================================
19 const PI
: f32 = 3.1415927410e+00; /* 0x40490fdb */
20 const PI_LO
: f32 = -8.7422776573e-08; /* 0xb3bbbd2e */
23 pub fn atan2f(y
: f32, x
: f32) -> f32 {
24 if x
.is_nan() || y
.is_nan() {
27 let mut ix
= x
.to_bits();
28 let mut iy
= y
.to_bits();
34 let m
= ((iy
>> 31) & 1) | ((ix
>> 30) & 2); /* 2*sign(x)+sign(y) */
41 0 | 1 => y
, /* atan(+-0,+anything)=+-0 */
42 2 => PI
, /* atan(+0,-anything) = pi */
43 3 | _
=> -PI
, /* atan(-0,-anything) =-pi */
48 return if m
& 1 != 0 { -PI / 2. }
else { PI / 2. }
;
52 return if iy
== 0x7f800000 {
54 0 => PI
/ 4., /* atan(+INF,+INF) */
55 1 => -PI
/ 4., /* atan(-INF,+INF) */
56 2 => 3. * PI
/ 4., /* atan(+INF,-INF)*/
57 3 | _
=> -3. * PI
/ 4., /* atan(-INF,-INF)*/
61 0 => 0., /* atan(+...,+INF) */
62 1 => -0., /* atan(-...,+INF) */
63 2 => PI
, /* atan(+...,-INF) */
64 3 | _
=> -PI
, /* atan(-...,-INF) */
69 if (ix
+ (26 << 23) < iy
) || (iy
== 0x7f800000) {
70 return if m
& 1 != 0 { -PI / 2. }
else { PI / 2. }
;
73 /* z = atan(|y/x|) with correct underflow */
74 let z
= if (m
& 2 != 0) && (iy
+ (26 << 23) < ix
) {
75 /*|y/x| < 0x1p-26, x < 0 */
81 0 => z
, /* atan(+,+) */
82 1 => -z
, /* atan(-,+) */
83 2 => PI
- (z
- PI_LO
), /* atan(+,-) */
84 _
=> (z
- PI_LO
) - PI
, /* case 3 */ /* atan(-,-) */