]>
git.proxmox.com Git - rustc.git/blob - src/libcompiler_builtins/libm/src/math/tan.rs
1 // origin: FreeBSD /usr/src/lib/msun/src/s_tan.c */
3 // ====================================================
4 // Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6 // Developed at SunPro, a Sun Microsystems, Inc. business.
7 // Permission to use, copy, modify, and distribute this
8 // software is freely granted, provided that this notice
10 // ====================================================
12 use super::{k_tan, rem_pio2}
;
15 // Return tangent function of x.
18 // k_tan ... tangent function on [-pi/4,pi/4]
19 // rem_pio2 ... argument reduction routine
22 // Let S,C and T denote the sin, cos and tan respectively on
23 // [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
24 // in [-pi/4 , +pi/4], and let n = k mod 4.
27 // n sin(x) cos(x) tan(x)
28 // ----------------------------------------------------------
33 // ----------------------------------------------------------
36 // Let trig be any of sin, cos, or tan.
37 // trig(+-INF) is NaN, with signals;
38 // trig(NaN) is that NaN;
41 // TRIG(x) returns trig(x) nearly rounded
43 pub fn tan(x
: f64) -> f64 {
44 let x1p120
= f32::from_bits(0x7b800000); // 0x1p120f === 2 ^ 120
46 let ix
= (f64::to_bits(x
) >> 32) as u32 & 0x7fffffff;
51 /* raise inexact if x!=0 and underflow if subnormal */
52 force_eval
!(if ix
< 0x00100000 {
59 return k_tan(x
, 0.0, 0);
62 /* tan(Inf or NaN) is NaN */
67 /* argument reduction */
68 let (n
, y0
, y1
) = rem_pio2(x
);