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

Commit 9f7020b

Browse files
committed
Add Small Conformance tests to Sqrt(f)
1 parent 4c8a973 commit 9f7020b

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/math/sqrt.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,4 +261,16 @@ mod tests {
261261
assert_eq!(sqrt(f), f);
262262
}
263263
}
264+
265+
#[test]
266+
fn conformance_tests() {
267+
let values = [3.14159265359, 10000.0, -1.0, INFINITY];
268+
let results = [4610661241675116657u64, 4636737291354636288u64,
269+
18444492273895866368u64, 9218868437227405312u64];
270+
271+
for i in 0..values.len() {
272+
let bits = f64::to_bits(sqrt(values[i]));
273+
assert_eq!(results[i], bits);
274+
}
275+
}
264276
}

src/math/sqrtf.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,15 @@ mod tests {
151151
assert_eq!(sqrtf(f), f);
152152
}
153153
}
154+
155+
#[test]
156+
fn conformance_tests() {
157+
let values = [3.14159265359f32, 10000.0f32, -1.0f32, INFINITY];
158+
let results = [1071833029u32, 1120403456u32, 4290772992u32, 2139095040u32];
159+
160+
for i in 0..values.len() {
161+
let bits = f32::to_bits(sqrtf(values[i]));
162+
assert_eq!(results[i], bits);
163+
}
164+
}
154165
}

0 commit comments

Comments
 (0)