@@ -428,9 +428,25 @@ fn interweave() {
428
428
429
429
#[ test]
430
430
fn nan_checks ( ) {
431
- let it = [ 1e+3 , -1e+3 , 1e-3 , -1e-3 ] ;
432
- // do these at f32 to faster approach bounds
433
- let fns: & [ ( & ' static str , fn ( & mut [ f32 ; 3 ] ) ) ] = & [
431
+ let fns_f64: & [ ( & ' static str , fn ( & mut [ f64 ; 3 ] ) ) ] = & [
432
+ ( "srgb_to_hsv" , srgb_to_hsv) ,
433
+ ( "hsv_to_srgb" , hsv_to_srgb) ,
434
+ ( "srgb_to_lrgb" , srgb_to_lrgb) ,
435
+ ( "lrgb_to_srgb" , lrgb_to_srgb) ,
436
+ ( "lrgb_to_xyz" , lrgb_to_xyz) ,
437
+ ( "xyz_to_lrgb" , xyz_to_lrgb) ,
438
+ ( "xyz_to_cielab" , xyz_to_cielab) ,
439
+ ( "cielab_to_xyz" , cielab_to_xyz) ,
440
+ ( "lab_to_lch" , lab_to_lch) ,
441
+ ( "lch_to_lab" , lch_to_lab) ,
442
+ ( "xyz_to_oklab" , xyz_to_oklab) ,
443
+ ( "oklab_to_xyz" , oklab_to_xyz) ,
444
+ ( "xyz_to_jzazbz" , xyz_to_jzazbz) ,
445
+ ( "jzazbz_to_xyz" , jzazbz_to_xyz) ,
446
+ ( "_lrgb_to_ictcp" , _lrgb_to_ictcp) ,
447
+ ( "_ictcp_to_lrgb" , _ictcp_to_lrgb) ,
448
+ ] ;
449
+ let fns_f32: & [ ( & ' static str , fn ( & mut [ f32 ; 3 ] ) ) ] = & [
434
450
( "srgb_to_hsv" , srgb_to_hsv) ,
435
451
( "hsv_to_srgb" , hsv_to_srgb) ,
436
452
( "srgb_to_lrgb" , srgb_to_lrgb) ,
@@ -444,26 +460,31 @@ fn nan_checks() {
444
460
( "xyz_to_oklab" , xyz_to_oklab) ,
445
461
( "oklab_to_xyz" , oklab_to_xyz) ,
446
462
// fails hard in the PQ function with (N/D)^P
447
- // Succeeds in F64 but graphics is almost always run in F32
448
463
//("xyz_to_jzazbz", xyz_to_jzazbz),
449
464
( "jzazbz_to_xyz" , jzazbz_to_xyz) ,
450
465
( "_lrgb_to_ictcp" , _lrgb_to_ictcp) ,
451
466
( "_ictcp_to_lrgb" , _ictcp_to_lrgb) ,
452
467
] ;
453
- for ( label, func) in fns {
454
- for a in it. iter ( ) {
455
- for b in it. iter ( ) {
456
- for c in it. iter ( ) {
457
- let from = [ * a, * b, * c] ;
458
- let mut to = from;
459
- func ( & mut to) ;
460
- if to. iter ( ) . any ( |c| !c. is_finite ( ) ) {
461
- panic ! ( "{} : {:?} -> {:?}" , label, from, to) ;
468
+ macro_rules! nan_checks {
469
+ ( $dtype: literal, $values: expr, $fns: expr) => {
470
+ for ( label, func) in $fns {
471
+ for a in $values. iter( ) {
472
+ for b in $values. iter( ) {
473
+ for c in $values. iter( ) {
474
+ let from = [ * a, * b, * c] ;
475
+ let mut to = from;
476
+ func( & mut to) ;
477
+ if to. iter( ) . any( |c| !c. is_finite( ) ) {
478
+ panic!( "{} {} : {:?} -> {:?}" , $dtype, label, from, to) ;
479
+ }
480
+ }
462
481
}
463
482
}
464
483
}
465
- }
484
+ } ;
466
485
}
486
+ nan_checks ! ( "F32" , [ 1e+3 , -1e+3 , 1e-3 , -1e-3 ] , fns_f32) ;
487
+ nan_checks ! ( "F64" , [ 1e+3 , -1e+3 , 1e-3 , -1e-3 ] , fns_f64) ;
467
488
}
468
489
469
490
#[ test]
0 commit comments