Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit 1c2c6a0

Browse files
authored
fix type of constants in ported sincosf (#331)
* fix type of constants in ported sincosf
1 parent 1583925 commit 1c2c6a0

File tree

1 file changed

+21
-29
lines changed

1 file changed

+21
-29
lines changed

libm/src/math/sincosf.rs

+21-29
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
use super::{k_cosf, k_sinf, rem_pio2f};
1818

1919
/* Small multiples of pi/2 rounded to double precision. */
20-
const PI_2: f32 = 0.5 * 3.1415926535897931160E+00;
21-
const S1PIO2: f32 = 1.0 * PI_2; /* 0x3FF921FB, 0x54442D18 */
22-
const S2PIO2: f32 = 2.0 * PI_2; /* 0x400921FB, 0x54442D18 */
23-
const S3PIO2: f32 = 3.0 * PI_2; /* 0x4012D97C, 0x7F3321D2 */
24-
const S4PIO2: f32 = 4.0 * PI_2; /* 0x401921FB, 0x54442D18 */
20+
const PI_2: f64 = 0.5 * 3.1415926535897931160E+00;
21+
const S1PIO2: f64 = 1.0 * PI_2; /* 0x3FF921FB, 0x54442D18 */
22+
const S2PIO2: f64 = 2.0 * PI_2; /* 0x400921FB, 0x54442D18 */
23+
const S3PIO2: f64 = 3.0 * PI_2; /* 0x4012D97C, 0x7F3321D2 */
24+
const S4PIO2: f64 = 4.0 * PI_2; /* 0x401921FB, 0x54442D18 */
2525

2626
/// Both the sine and cosine of `x` (f32).
2727
///
@@ -59,21 +59,21 @@ pub fn sincosf(x: f32) -> (f32, f32) {
5959
if ix <= 0x4016cbe3 {
6060
/* |x| ~<= 3pi/4 */
6161
if sign {
62-
s = -k_cosf((x + S1PIO2) as f64);
63-
c = k_sinf((x + S1PIO2) as f64);
62+
s = -k_cosf(x as f64 + S1PIO2);
63+
c = k_sinf(x as f64 + S1PIO2);
6464
} else {
65-
s = k_cosf((S1PIO2 - x) as f64);
66-
c = k_sinf((S1PIO2 - x) as f64);
65+
s = k_cosf(S1PIO2 - x as f64);
66+
c = k_sinf(S1PIO2 - x as f64);
6767
}
6868
}
6969
/* -sin(x+c) is not correct if x+c could be 0: -0 vs +0 */
7070
else {
7171
if sign {
72-
s = -k_sinf((x + S2PIO2) as f64);
73-
c = -k_cosf((x + S2PIO2) as f64);
72+
s = -k_sinf(x as f64 + S2PIO2);
73+
c = -k_cosf(x as f64 + S2PIO2);
7474
} else {
75-
s = -k_sinf((x - S2PIO2) as f64);
76-
c = -k_cosf((x - S2PIO2) as f64);
75+
s = -k_sinf(x as f64 - S2PIO2);
76+
c = -k_cosf(x as f64 - S2PIO2);
7777
}
7878
}
7979

@@ -85,19 +85,19 @@ pub fn sincosf(x: f32) -> (f32, f32) {
8585
if ix <= 0x40afeddf {
8686
/* |x| ~<= 7*pi/4 */
8787
if sign {
88-
s = k_cosf((x + S3PIO2) as f64);
89-
c = -k_sinf((x + S3PIO2) as f64);
88+
s = k_cosf(x as f64 + S3PIO2);
89+
c = -k_sinf(x as f64 + S3PIO2);
9090
} else {
91-
s = -k_cosf((x - S3PIO2) as f64);
92-
c = k_sinf((x - S3PIO2) as f64);
91+
s = -k_cosf(x as f64 - S3PIO2);
92+
c = k_sinf(x as f64 - S3PIO2);
9393
}
9494
} else {
9595
if sign {
96-
s = k_sinf((x + S4PIO2) as f64);
97-
c = k_cosf((x + S4PIO2) as f64);
96+
s = k_sinf(x as f64 + S4PIO2);
97+
c = k_cosf(x as f64 + S4PIO2);
9898
} else {
99-
s = k_sinf((x - S4PIO2) as f64);
100-
c = k_cosf((x - S4PIO2) as f64);
99+
s = k_sinf(x as f64 - S4PIO2);
100+
c = k_cosf(x as f64 - S4PIO2);
101101
}
102102
}
103103

@@ -131,14 +131,6 @@ pub fn sincosf(x: f32) -> (f32, f32) {
131131
#[cfg(test)]
132132
mod tests {
133133
use super::sincosf;
134-
use crate::_eqf;
135-
136-
#[test]
137-
fn with_pi() {
138-
let (s, c) = sincosf(core::f32::consts::PI);
139-
_eqf(s.abs(), 0.0).unwrap();
140-
_eqf(c, -1.0).unwrap();
141-
}
142134

143135
#[test]
144136
fn rotational_symmetry() {

0 commit comments

Comments
 (0)