Debian Codegraph @

debian/missing-sources/wide/tests/all_tests/t_f64x4.rs

raw
1 use core::f64;
2
3 use wide::*;
4
5 use bytemuck::*;
6
7 #[test]
8 fn size_align() {
9 assert_eq!(core::mem::size_of::<f64x4>(), 32);
10 assert_eq!(core::mem::align_of::<f64x4>(), 32);
11 }
12
13 #[test]
14 fn impl_debug_for_f64x4() {
15 let expected = "(1.0, 2.0, 3.0, 4.0)";
16 let actual = format!("{:?}", f64x4::from([1.0, 2.0, 3.0, 4.0]));
17 assert_eq!(expected, actual);
18
19 let expected = "(1.000, 2.000, 3.000, 4.000)";
20 let actual = format!("{:.3?}", f64x4::from([1.0, 2.0, 3.0, 4.0]));
21 assert_eq!(expected, actual);
22 }
23
24 #[test]
25 fn impl_add_for_f64x4() {
26 let a = f64x4::from([1.0, 2.0, 3.0, 4.0]);
27 let b = f64x4::from([5.0, 6.0, 7.0, 8.0]);
28 let expected = f64x4::from([6.0, 8.0, 10.0, 12.0]);
29 let actual = a + b;
30 assert_eq!(expected, actual);
31 }
32
33 #[test]
34 fn impl_sub_for_f64x4() {
35 let a = f64x4::from([1.0, 2.0, 3.0, 4.0]);
36 let b = f64x4::from([5.0, 7.0, 17.0, 1.0]);
37 let expected = f64x4::from([-4.0, -5.0, -14.0, 3.0]);
38 let actual = a - b;
39 assert_eq!(expected, actual);
40 }
41
42 #[test]
43 fn impl_mul_for_f64x4() {
44 let a = f64x4::from([1.0, 2.0, 3.0, 4.0]);
45 let b = f64x4::from([5.0, 7.0, 17.0, 1.0]);
46 let expected = f64x4::from([5.0, 14.0, 51.0, 4.0]);
47 let actual = a * b;
48 assert_eq!(expected, actual);
49 }
50
51 #[test]
52 fn impl_div_for_f64x4() {
53 let a = f64x4::from([4.0, 9.0, 10.0, 12.0]);
54 let b = f64x4::from([2.0, 2.0, 5.0, -3.0]);
55 let expected = f64x4::from([2.0, 4.5, 2.0, -4.0]);
56 let actual = a / b;
57 assert_eq!(expected, actual);
58 }
59
60 #[test]
61 fn impl_sub_const_for_f64x4() {
62 let a = f64x4::from([1.0, 2.0, 3.0, 4.0]);
63 let expected = f64x4::from([-1.0, 0.0, 1.0, 2.0]);
64 let actual = a - 2.0;
65 assert_eq!(expected, actual);
66 }
67
68 #[test]
69 fn impl_mul_const_for_f64x4() {
70 let a = f64x4::from([1.0, 2.0, 3.0, 4.0]);
71 let expected = f64x4::from([2.0, 4.0, 6.0, 8.0]);
72 let actual = a * 2.0;
73 assert_eq!(expected, actual);
74 }
75
76 #[test]
77 fn impl_div_const_for_f64x4() {
78 let a = f64x4::from([1.0, 2.0, 3.0, 4.0]);
79 let expected = f64x4::from([0.5, 1.0, 1.5, 2.0]);
80 let actual = a / 2.0;
81 assert_eq!(expected, actual);
82 }
83
84 #[test]
85 fn impl_bitand_for_f64x4() {
86 let a = f64x4::from([0.0, 0.0, 1.0, 1.0]);
87 let b = f64x4::from([0.0, 1.0, 0.0, 1.0]);
88 let expected = f64x4::from([0.0, 0.0, 0.0, 1.0]);
89 let actual = a & b;
90 assert_eq!(expected, actual);
91 }
92
93 #[test]
94 fn impl_bitor_for_f64x4() {
95 let a = f64x4::from([0.0, 0.0, 1.0, 1.0]);
96 let b = f64x4::from([0.0, 1.0, 0.0, 1.0]);
97 let expected = f64x4::from([0.0, 1.0, 1.0, 1.0]);
98 let actual = a | b;
99 assert_eq!(expected, actual);
100 }
101
102 #[test]
103 fn impl_bitxor_for_f64x4() {
104 let a = f64x4::from([0.0, 0.0, 1.0, 1.0]);
105 let b = f64x4::from([0.0, 1.0, 0.0, 1.0]);
106 let expected = f64x4::from([0.0, 1.0, 1.0, 0.0]);
107 let actual = a ^ b;
108 assert_eq!(expected, actual);
109 }
110
111 #[test]
112 fn impl_f64x4_cmp_eq() {
113 let a = f64x4::from([1.0, 2.0, 3.0, 4.0]);
114 let b = f64x4::from([2.0, 2.0, 2.0, 2.0]);
115 let expected: [i64; 4] = [0, -1, 0, 0];
116 let actual: [i64; 4] = cast(a.cmp_eq(b));
117 assert_eq!(expected, actual);
118 }
119
120 #[test]
121 fn impl_f64x4_cmp_ne() {
122 let a = f64x4::from([1.0, 2.0, 3.0, 4.0]);
123 let b = f64x4::from([2.0, 2.0, 2.0, 2.0]);
124 let expected: [i64; 4] = [-1, 0, -1, -1];
125 let actual: [i64; 4] = cast(a.cmp_ne(b));
126 assert_eq!(expected, actual);
127 }
128
129 #[test]
130 fn impl_f64x4_cmp_ge() {
131 let a = f64x4::from([1.0, 2.0, 3.0, 4.0]);
132 let b = f64x4::from([2.0, 2.0, 2.0, 2.0]);
133 let expected: [i64; 4] = [0, -1, -1, -1];
134 let actual: [i64; 4] = cast(a.cmp_ge(b));
135 assert_eq!(expected, actual);
136 }
137
138 #[test]
139 fn impl_f64x4_cmp_gt() {
140 let a = f64x4::from([1.0, 2.0, 3.0, 4.0]);
141 let b = f64x4::from([2.0, 2.0, 2.0, 2.0]);
142 let expected: [i64; 4] = [0, 0, -1, -1];
143 let actual: [i64; 4] = cast(a.cmp_gt(b));
144 assert_eq!(expected, actual);
145 }
146
147 #[test]
148 fn impl_f64x4_cmp_le() {
149 let a = f64x4::from([1.0, 2.0, 3.0, 4.0]);
150 let b = f64x4::from([2.0, 2.0, 2.0, 2.0]);
151 let expected: [i64; 4] = [-1, -1, 0, 0];
152 let actual: [i64; 4] = cast(a.cmp_le(b));
153 assert_eq!(expected, actual);
154 }
155
156 #[test]
157 fn impl_f64x4_cmp_lt() {
158 let a = f64x4::from([1.0, 2.0, 3.0, 4.0]);
159 let b = f64x4::from([2.0, 2.0, 2.0, 2.0]);
160 let expected: [i64; 4] = [-1, 0, 0, 0];
161 let actual: [i64; 4] = cast(a.cmp_lt(b));
162 assert_eq!(expected, actual);
163
164 let expected: [i64; 4] = [0, 0, 0, 0];
165 let actual: [i64; 4] = cast(a.cmp_lt(a));
166 assert_eq!(expected, actual);
167 }
168
169 #[test]
170 fn impl_f64x4_blend() {
171 let use_t: f64 = f64::from_bits(u64::MAX);
172 let t = f64x4::from([1.0, 2.0, 3.0, 4.0]);
173 let f = f64x4::from([5.0, 6.0, 7.0, 8.0]);
174 let mask = f64x4::from([use_t, 0.0, use_t, 0.0]);
175 let expected = f64x4::from([1.0, 6.0, 3.0, 8.0]);
176 let actual = mask.blend(t, f);
177 assert_eq!(expected, actual);
178 }
179
180 #[test]
181 fn impl_f64x4_abs() {
182 let a = f64x4::from([-1.0, 2.0, -3.5, f64::NEG_INFINITY]);
183 let expected = f64x4::from([1.0, 2.0, 3.5, f64::INFINITY]);
184 let actual = a.abs();
185 assert_eq!(expected, actual);
186 }
187
188 #[test]
189 fn impl_f64x4_floor() {
190 let a = f64x4::from([-1.1, 60.9, 1.1, f64::INFINITY]);
191 let expected = f64x4::from([-2.0, 60.0, 1.0, f64::INFINITY]);
192 let actual = a.floor();
193 assert_eq!(expected, actual);
194 }
195
196 #[test]
197 fn impl_f64x4_ceil() {
198 let a = f64x4::from([-1.1, 60.9, 1.1, f64::NEG_INFINITY]);
199 let expected = f64x4::from([-1.0, 61.0, 2.0, f64::NEG_INFINITY]);
200 let actual = a.ceil();
201 assert_eq!(expected, actual);
202 }
203
204 #[test]
205 fn impl_f64x4_fast_max() {
206 let a = f64x4::from([1.0, 5.0, 3.0, -0.0]);
207 let b = f64x4::from([2.0, f64::NEG_INFINITY, f64::INFINITY, 0.0]);
208 let expected = f64x4::from([2.0, 5.0, f64::INFINITY, 0.0]);
209 let actual = a.fast_max(b);
210 assert_eq!(expected, actual);
211 }
212
213 #[test]
214 fn impl_f64x4_max() {
215 let a = f64x4::from([1.0, 5.0, 3.0, -0.0]);
216 let b = f64x4::from([2.0, f64::NEG_INFINITY, f64::INFINITY, 0.0]);
217 let expected = f64x4::from([2.0, 5.0, f64::INFINITY, 0.0]);
218 let actual = a.max(b);
219 assert_eq!(expected, actual);
220
221 let a = f64x4::from([f64::NAN, 5.0, f64::INFINITY, f64::NAN]);
222 let b = f64x4::from([2.0, f64::NAN, f64::NAN, f64::INFINITY]);
223 let expected = f64x4::from([2.0, 5.0, f64::INFINITY, f64::INFINITY]);
224 let actual = a.max(b);
225 assert_eq!(expected, actual);
226 }
227
228 #[test]
229 fn impl_f64x4_fast_min() {
230 let a = f64x4::from([1.0, 5.0, 3.0, -0.0]);
231 let b = f64x4::from([2.0, f64::NEG_INFINITY, f64::INFINITY, 0.0]);
232 let expected = f64x4::from([1.0, f64::NEG_INFINITY, 3.0, -0.0]);
233 let actual = a.fast_min(b);
234 assert_eq!(expected, actual);
235 }
236
237 #[test]
238 fn impl_f64x4_min() {
239 let a = f64x4::from([1.0, 5.0, 3.0, -0.0]);
240 let b = f64x4::from([2.0, f64::NEG_INFINITY, f64::INFINITY, 0.0]);
241 let expected = f64x4::from([1.0, f64::NEG_INFINITY, 3.0, -0.0]);
242 let actual = a.min(b);
243 assert_eq!(expected, actual);
244
245 let a = f64x4::from([f64::NAN, 5.0, f64::INFINITY, f64::NAN]);
246 let b = f64x4::from([2.0, f64::NAN, f64::NAN, f64::INFINITY]);
247 let expected = f64x4::from([2.0, 5.0, f64::INFINITY, f64::INFINITY]);
248 let actual = a.min(b);
249 assert_eq!(expected, actual);
250 }
251
252 #[test]
253 fn impl_f64x4_is_nan() {
254 let a = f64x4::from([0.0, f64::NAN, f64::NAN, 0.0]);
255 let expected = [0, u64::MAX, u64::MAX, 0];
256 let actual: [u64; 4] = cast(a.is_nan());
257 assert_eq!(expected, actual);
258 }
259
260 #[test]
261 fn impl_f64x4_is_finite() {
262 let a = f64x4::from([f64::NAN, 1.0, f64::INFINITY, f64::NEG_INFINITY]);
263 let expected = [0, u64::MAX, 0, 0];
264 let actual: [u64; 4] = cast(a.is_finite());
265 assert_eq!(expected, actual);
266 }
267
268 #[test]
269 fn impl_f64x4_round() {
270 let a = f64x4::from([1.1, 2.5, 3.7, 4.0]);
271 let expected = f64x4::from([1.0, 2.0, 4.0, 4.0]);
272 let actual = a.round();
273 assert_eq!(expected, actual);
274 //
275 let a = f64x4::from([-1.1, -2.5, -3.7, -4.0]);
276 let expected = f64x4::from([-1.0, -2.0, -4.0, -4.0]);
277 let actual = a.round();
278 assert_eq!(expected, actual);
279 //
280 let a = f64x4::from([f64::INFINITY, f64::NEG_INFINITY, 5.5, 5.0]);
281 let expected = f64x4::from([f64::INFINITY, f64::NEG_INFINITY, 6.0, 5.0]);
282 let actual = a.round();
283 assert_eq!(expected, actual);
284 //
285 let a = f64x4::from(f64::NAN);
286 let expected: [u64; 4] = [u64::MAX; 4];
287 let actual: [u64; 4] = cast(a.round().is_nan());
288 assert_eq!(expected, actual);
289 //
290 let a = f64x4::from(-0.0);
291 let expected = a;
292 let actual = a.round();
293 assert_eq!(expected, actual);
294 }
295
296 #[test]
297 fn impl_f64x4_round_int() {
298 for (f, i) in [
299 (1.0, 1i64),
300 (1.1, 1),
301 (-2.1, -2),
302 (2.5, 2),
303 (0.0, 0),
304 (-0.0, 0),
305 (f64::NAN, 0),
306 (f64::INFINITY, i64::MAX),
307 (f64::NEG_INFINITY, i64::MIN),
308 ]
309 .iter()
310 .copied()
311 {
312 let a = f64x4::from(f);
313 let expected = i64x4::from(i);
314 let actual = a.round_int();
315 assert_eq!(expected, actual);
316 }
317 }
318
319 #[test]
320 fn impl_f64x4_mul_add() {
321 let a = f64x4::from([2.0, 3.0, 4.0, 5.0]);
322 let b = f64x4::from([4.0, 5.0, 6.0, 7.0]);
323 let c = f64x4::from([1.0, 1.0, 1.0, 1.0]);
324 let expected = f64x4::from([9.0, 16.0, 25.0, 36.0]);
325 let actual = a.mul_add(b, c);
326 assert_eq!(expected, actual);
327 }
328
329 #[test]
330 fn impl_f64x4_mul_neg_add() {
331 let a = f64x4::from([2.0, 3.0, 4.0, 5.0]);
332 let b = f64x4::from([4.0, 5.0, 6.0, 7.0]);
333 let c = f64x4::from([1.0, 1.0, 1.0, 1.0]);
334 let expected = f64x4::from([-7.0, -14.0, -23.0, -34.0]);
335 let actual = a.mul_neg_add(b, c);
336 assert_eq!(expected, actual);
337 }
338
339 #[test]
340 fn impl_f64x4_flip_signs() {
341 let a = f64x4::from([1.0, 1.0, -1.0, -1.0]);
342 let b = f64x4::from([2.0, -3.0, 4.0, -5.0]);
343 let expected = f64x4::from([1.0, -1.0, -1.0, 1.0]);
344 let actual = a.flip_signs(b);
345 assert_eq!(expected, actual);
346 }
347
348 #[test]
349 fn impl_f64x4_copysign() {
350 let a = f64x4::from([1.0, 1.0, -1.0, -1.0]);
351 let b = f64x4::from([2.0, -3.0, 4.0, -5.0]);
352 let expected = f64x4::from([1.0, -1.0, 1.0, -1.0]);
353 let actual = a.copysign(b);
354 assert_eq!(expected, actual);
355 }
356
357 // FIXME: remove cfg requirement once masks as their own types are implemented
358 #[cfg(target_feature = "avx")]
359 #[test]
360 fn impl_f64x4_asin_acos() {
361 let inc = 1.0 / 2501.0 / 4.0;
362 for x in -2500..=2500 {
363 let base = (x * 4) as f64 * inc;
364 let origs = [base, base + inc, base + 2.0 * inc, base + 3.0 * inc];
365 let (actual_asins, actual_acoses) = f64x4::from(origs).asin_acos();
366 for i in 0..4 {
367 let orig = origs[i];
368 let check = |name: &str, vals: f64x4, expected: f64| {
369 let actual_arr: [f64; 4] = cast(vals);
370 let actual = actual_arr[i];
371 assert!(
372 (actual - expected).abs() < 0.0000006,
373 "Wanted {name}({orig}) to be {expected} but got {actual}",
374 name = name,
375 orig = orig,
376 expected = expected,
377 actual = actual
378 );
379 };
380 check("asin", actual_asins, orig.asin());
381 check("acos", actual_acoses, orig.acos());
382 }
383 }
384 }
385
386 // FIXME: remove cfg requirement once masks as their own types are implemented
387 #[cfg(target_feature = "avx")]
388 #[test]
389 fn impl_f64x4_asin() {
390 let inc = 1.0 / 2501.0 / 4.0;
391 for x in -2500..=2500 {
392 let base = (x * 4) as f64 * inc;
393 let origs = [base, base + inc, base + 2.0 * inc, base + 3.0 * inc];
394 let actual_asins = f64x4::from(origs).asin();
395 for i in 0..4 {
396 let orig = origs[i];
397 let check = |name: &str, vals: f64x4, expected: f64| {
398 let actual_arr: [f64; 4] = cast(vals);
399 let actual = actual_arr[i];
400 assert!(
401 (actual - expected).abs() < 0.0000006,
402 "Wanted {name}({orig}) to be {expected} but got {actual}",
403 name = name,
404 orig = orig,
405 expected = expected,
406 actual = actual
407 );
408 };
409 check("asin", actual_asins, orig.asin());
410 }
411 }
412 }
413
414 // FIXME: remove cfg requirement once masks as their own types are implemented
415 #[cfg(target_feature = "avx")]
416 #[test]
417 fn impl_f64x4_acos() {
418 let inc = 1.0 / 2501.0 / 4.0;
419 for x in -2500..=2500 {
420 let base = (x * 4) as f64 * inc;
421 let origs = [base, base + inc, base + 2.0 * inc, base + 3.0 * inc];
422 let actual_acoses = f64x4::from(origs).acos();
423 for i in 0..4 {
424 let orig = origs[i];
425 let check = |name: &str, vals: f64x4, expected: f64| {
426 let actual_arr: [f64; 4] = cast(vals);
427 let actual = actual_arr[i];
428 assert!(
429 (actual - expected).abs() < 0.0000006,
430 "Wanted {name}({orig}) to be {expected} but got {actual}",
431 name = name,
432 orig = orig,
433 expected = expected,
434 actual = actual
435 );
436 };
437 check("acos", actual_acoses, orig.acos());
438 }
439 }
440 }
441
442 // FIXME: remove cfg requirement once masks as their own types are implemented
443 #[cfg(target_feature = "avx")]
444 #[test]
445 fn impl_f64x4_atan() {
446 let inc = 1.0 / 2501.0 / 4.0;
447 for x in -2500..=2500 {
448 let base = (x * 4) as f64 * inc;
449 let origs = [base, base + inc, base + 2.0 * inc, base + 3.0 * inc];
450 let actual_atans = f64x4::from(origs).atan();
451 for i in 0..4 {
452 let orig = origs[i];
453 let check = |name: &str, vals: f64x4, expected: f64| {
454 let actual_arr: [f64; 4] = cast(vals);
455 let actual = actual_arr[i];
456 assert!(
457 (actual - expected).abs() < 0.000000000000001,
458 "Wanted {name}({orig}) to be {expected} but got {actual}",
459 name = name,
460 orig = orig,
461 expected = expected,
462 actual = actual
463 );
464 };
465 check("atan", actual_atans, orig.atan());
466 }
467 }
468 }
469
470 // FIXME: remove cfg requirement once masks as their own types are implemented
471 #[cfg(target_feature = "avx")]
472 #[test]
473 fn impl_f64x4_atan2() {
474 let inc_y = 1.0 / 51.0 / 4.0;
475 let inc_x = 1.0 / 2501.0 / 4.0;
476 for y in -50..=50 {
477 let base_y = (y * 4) as f64 * inc_y;
478 let origs_y =
479 [base_y, base_y + inc_y, base_y + 2.0 * inc_y, base_y + 3.0 * inc_y];
480 let actual_y = f64x4::from(origs_y);
481 for x in -2500..=2500 {
482 let base_x = (x * 4) as f64 * inc_x;
483 let origs_x =
484 [base_x, base_x + inc_x, base_x + 2.0 * inc_x, base_x + 3.0 * inc_x];
485 let actual_x = f64x4::from(origs_x);
486 let actual_atan2s = actual_y.atan2(actual_x);
487 for i in 0..4 {
488 let orig_y = origs_y[i];
489 let orig_x = origs_x[i];
490 let check = |name: &str, vals: f64x4, expected: f64| {
491 let actual_arr: [f64; 4] = cast(vals);
492 let actual = actual_arr[i];
493 assert!(
494 (actual - expected).abs() < 0.000000000000001,
495 "Wanted {name}({orig_y}, {orig_x}) to be {expected} but got {actual}",
496 name = name,
497 orig_y = orig_y,
498 orig_x = orig_x,
499 expected = expected,
500 actual = actual
501 );
502 };
503 check("atan2", actual_atan2s, orig_y.atan2(orig_x));
504 }
505 }
506 }
507 }
508
509 #[test]
510 fn impl_f64x4_sin_cos() {
511 for x in -2500..=2500 {
512 let base = (x * 4) as f64;
513 let angles = [base, base + 1.0, base + 2.0, base + 3.0];
514 let (actual_sins, actual_coses) = f64x4::from(angles).sin_cos();
515 for i in 0..4 {
516 let angle = angles[i];
517 let check = |name: &str, vals: f64x4, expected: f64| {
518 let actual_arr: [f64; 4] = cast(vals);
519 let actual = actual_arr[i];
520 assert!(
521 (actual - expected).abs() < 0.00000006,
522 "Wanted {name}({angle}) to be {expected} but got {actual}",
523 name = name,
524 angle = angle,
525 expected = expected,
526 actual = actual
527 );
528 };
529 check("sin", actual_sins, angle.sin());
530 check("cos", actual_coses, angle.cos());
531 }
532 }
533 }
534
535 #[test]
536 fn impl_f64x4_to_degrees() {
537 let pi = core::f64::consts::PI;
538 let a = f64x4::from([0.0, pi / 2.0, pi, 2.0 * pi]);
539 let expected = f64x4::from([0.0, 90.0, 180.0, 360.0]);
540 let actual = a.to_degrees();
541 assert_eq!(expected, actual);
542 }
543
544 #[test]
545 fn impl_f64x4_to_radians() {
546 let pi = core::f64::consts::PI;
547 let a = f64x4::from([0.0, 90.0, 180.0, 360.0]);
548 let expected = f64x4::from([0.0, pi / 2.0, pi, 2.0 * pi]);
549 let actual = a.to_radians();
550 assert_eq!(expected, actual);
551 }
552
553 #[test]
554 fn impl_f64x4_sqrt() {
555 for (f, e) in [
556 (f64::INFINITY, f64::INFINITY),
557 (0.0, 0.0),
558 (-0.0, -0.0),
559 (4.0, 2.0),
560 (9.0, 3.0),
561 (16.0, 4.0),
562 (25.0, 5.0),
563 (5000.0 * 5000.0, 5000.0),
564 ]
565 .iter()
566 .copied()
567 {
568 let expected = f64x4::from(e);
569 let actual = f64x4::from(f).sqrt();
570 assert_eq!(expected, actual);
571 }
572 assert_eq!(
573 cast::<_, i64x4>(f64x4::from(f64::NAN).sqrt().is_nan()),
574 i64x4::from(-1)
575 );
576 assert_eq!(
577 cast::<_, i64x4>(f64x4::from(f64::NEG_INFINITY).sqrt().is_nan()),
578 i64x4::from(-1)
579 );
580 assert_eq!(
581 cast::<_, i64x4>(f64x4::from(-1.0).sqrt().is_nan()),
582 i64x4::from(-1)
583 );
584 }
585
586 #[test]
587 fn impl_f64x4_exp() {
588 for f in [(-2.0), (-1.0), (0.0), (1.0), (1.5), (2.0), (10.0)].iter().copied()
589 {
590 let expected = f64x4::from((f as f64).exp());
591 let actual = f64x4::from(f).exp();
592 let diff_from_std: [f64; 4] = cast((actual - expected).abs());
593 assert!(diff_from_std[0] < 0.000000000000001);
594 }
595 }
596
597 #[test]
598 fn test_f64x4_move_mask() {
599 let a = f64x4::from([-1.0, 0.0, -2.0, -3.0]);
600 let expected = 0b1101;
601 let actual = a.move_mask();
602 assert_eq!(expected, actual);
603 //
604 let a = f64x4::from([1.0, 0.0, 2.0, -3.0]);
605 let expected = 0b1000;
606 let actual = a.move_mask();
607 assert_eq!(expected, actual);
608 }
609
610 #[test]
611 fn test_f64x4_any() {
612 let a = f64x4::from([-1.0, 0.0, -2.0, f64::NAN]).is_nan();
613 assert!(a.any());
614 //
615 let a = f64x4::from([1.0, 0.0, 2.0, 3.0]).is_nan();
616 assert!(!a.any());
617 }
618
619 #[test]
620 fn test_f64x4_all() {
621 let a = f64x4::from([f64::NAN, f64::NAN, f64::NAN, f64::NAN]).is_nan();
622 assert!(a.all());
623 //
624 let a = f64x4::from([1.0, -0.0, 2.0, f64::NAN]).is_nan();
625 assert!(!a.all());
626 }
627
628 #[test]
629 fn test_f64x4_none() {
630 let a = f64x4::from([1.0, 0.0, 2.0, 3.0]).is_nan();
631 assert!(a.none());
632 //
633 let a = f64x4::from([1.0, -0.0, 2.0, f64::NAN]).is_nan();
634 assert!(!a.none());
635 }
636
637 #[test]
638 fn impl_f64x4_ln() {
639 if cfg!(target_feature = "sse") {
640 for f in [0.1, 0.5, 1.0, 2.718282, 10.0, 35.0, 1250.0].iter().copied() {
641 let expected = f64x4::from((f as f64).ln());
642 let actual = f64x4::from(f).ln();
643 let diff_from_std: [f64; 4] = cast((actual - expected).abs());
644 assert!(diff_from_std[0] < 0.00000000001);
645 }
646 }
647 }
648
649 #[test]
650 fn impl_f64x4_pow_single() {
651 for f in [0.1, 0.5, 1.0, 2.718282, 3.0, 4.0, 2.5, -1.0].iter().copied() {
652 let expected = f64x4::splat(2.0 as f64).powf(f);
653 let actual = f64x4::from(2.0_f64.powf(f));
654 let diff_from_std: [f64; 4] = cast((actual - expected).abs());
655 assert!(diff_from_std[0] < 0.000001);
656 }
657 }
658
659 #[cfg(target_feature = "sse")]
660 #[test]
661 // NOTE this fails due the signbit not working with the non-sse blend
662 // it only affects the case where there is a nan result
663 fn impl_f64x4_pow_nan() {
664 for f in [3.4].iter().copied() {
665 let expected: [f64; 4] = cast(f64x4::splat(-4.5_f64).powf(f));
666 let actual = (-4.5_f64).powf(f);
667 assert!(expected[0].is_nan());
668 assert!(actual.is_nan());
669 }
670 }
671
672 #[test]
673 fn impl_f64x4_pow_multiple() {
674 let p = f64x4::from([29.0, 0.1, 0.5, 1.0]);
675 let f = f64x4::from([1.2, 2.0, 3.0, 1.5]);
676 let res = f.pow_f64x4(p);
677
678 let p: [f64; 4] = cast(p);
679 let f: [f64; 4] = cast(f);
680 let res: [f64; 4] = cast(res);
681 for i in 0..p.len() {
682 let expected = f[i].powf(p[i]);
683 if expected.is_nan() && res[i].is_nan() {
684 assert!(true);
685 continue;
686 }
687 if !(expected.is_nan() && res[i].is_nan()) {
688 assert!((expected - res[i]).abs() < 0.0001);
689 }
690 }
691
692 let p = f64x4::from([2.718282, -0.2, -1.5, 3.4]);
693 let f = f64x4::from([9.2, 6.1, 2.5, 4.5]);
694 let res = f.pow_f64x4(p);
695
696 let p: [f64; 4] = cast(p);
697 let f: [f64; 4] = cast(f);
698 let res: [f64; 4] = cast(res);
699 for i in 0..p.len() {
700 let expected = f[i].powf(p[i]);
701 if !(expected.is_nan() && res[i].is_nan()) {
702 assert!((expected - res[i]).abs() < 0.0001);
703 }
704 }
705 }
706
707 #[test]
708 fn impl_f64x4_reduce_add() {
709 let p = f64x4::splat(0.001);
710 assert_eq!(p.reduce_add(), 0.004);
711 }
712
713 #[test]
714 fn impl_f64x4_sum() {
715 let mut p = Vec::with_capacity(250_000);
716 for _ in 0..250_000 {
717 p.push(f64x4::splat(0.001));
718 }
719 let now = std::time::Instant::now();
720 let sum: f64 = p.iter().map(|x| x.reduce_add()).sum();
721 let duration = now.elapsed().as_micros();
722 println!("Time take {} {}us", sum, duration);
723
724 let p = vec![0.001; 1_000_000];
725 let now = std::time::Instant::now();
726 let sum2: f64 = p.iter().sum();
727 let duration = now.elapsed().as_micros();
728 println!("Time take {} {}us", sum2, duration);
729 }
730
731 #[test]
732 fn impl_f64x4_from_i32x4() {
733 let i = i32x4::from([1, 2, 3, 4]);
734 let f = f64x4::from([1.0, 2.0, 3.0, 4.0]);
735 assert_eq!(f64x4::from(i), f);
736 assert_eq!(f64x4::from_i32x4(i), f);
737 }
738
739 #[cfg(feature = "serde")]
740 #[test]
741 fn impl_f64x4_ser_de_roundtrip() {
742 let serialized =
743 bincode::serialize(&f64x4::ZERO).expect("serialization failed");
744 let deserialized =
745 bincode::deserialize(&serialized).expect("deserializaion failed");
746 assert_eq!(f64x4::ZERO, deserialized);
747 }