@@ -421,12 +421,12 @@ mod tests {
421
421
const NEG_ZERO : & [ f64 ] = & [ -0.0 ] ;
422
422
const POS_ONE : & [ f64 ] = & [ 1.0 ] ;
423
423
const NEG_ONE : & [ f64 ] = & [ -1.0 ] ;
424
- const POS_FLOATS : & [ f64 ] = & [ E , PI , MAX ] ;
425
- const NEG_FLOATS : & [ f64 ] = & [ -E , -PI , MIN ] ;
424
+ const POS_FLOATS : & [ f64 ] = & [ 99.0 / 70.0 , E , PI ] ;
425
+ const NEG_FLOATS : & [ f64 ] = & [ -99.0 / 70.0 , -E , - PI ] ;
426
426
const POS_SMALL_FLOATS : & [ f64 ] = & [ ( 1.0 / 2.0 ) , MIN_POSITIVE , EPSILON ] ;
427
427
const NEG_SMALL_FLOATS : & [ f64 ] = & [ -( 1.0 / 2.0 ) , -MIN_POSITIVE , -EPSILON ] ;
428
- const POS_EVENS : & [ f64 ] = & [ 2.0 , 6.0 , 8.0 , 10.0 , 22.0 , 100.0 ] ;
429
- const NEG_EVENS : & [ f64 ] = & [ - 8 .0, -2.0 ] ;
428
+ const POS_EVENS : & [ f64 ] = & [ 2.0 , 6.0 , 8.0 , 10.0 , 22.0 , 100.0 , MAX ] ;
429
+ const NEG_EVENS : & [ f64 ] = & [ MIN , - 100.0 , - 22.0 , - 10.0 , - 8.0 , - 6 .0, -2.0 ] ;
430
430
const POS_ODDS : & [ f64 ] = & [ 3.0 , 7.0 ] ;
431
431
const NEG_ODDS : & [ f64 ] = & [ -7.0 , -3.0 ] ;
432
432
const NANS : & [ f64 ] = & [ NAN ] ;
@@ -574,7 +574,7 @@ mod tests {
574
574
test_sets_as_exponent ( 0.0 , & POS [ 1 ..] , 0.0 ) ;
575
575
576
576
// (+0 ^ anything negative but 0 and NAN should be Infinity)
577
- // (this should panic because we're dividing by zero but won't because release mode, I think )
577
+ // (this should panic because we're dividing by zero)
578
578
test_sets_as_exponent ( 0.0 , & NEG [ 1 ..] , INFINITY ) ;
579
579
580
580
// Negative Zero as the base:
@@ -593,10 +593,39 @@ mod tests {
593
593
test_sets_as_exponent ( -0.0 , & [ NEG_ODDS ] , NEG_INFINITY ) ;
594
594
}
595
595
596
+ #[ test]
597
+ fn special_cases ( ) {
598
+ // / 20. (anything) ** 1 is (anything)
599
+ // One as the exponent:
600
+ // (anything ^ 1 should be anything - i.e. the base)
601
+ test_sets ( ALL , & |v : f64 | pow ( v, 1.0 ) , & |v : f64 | v) ;
602
+
603
+ // / 21. (anything) ** -1 is 1/(anything)
604
+ // Negative One as the exponent:
605
+ // (anything ^ -1 should be 1/anything)
606
+ test_sets ( ALL , & |v : f64 | pow ( v, -1.0 ) , & |v : f64 | 1.0 / v) ;
607
+
608
+ // / 22. (-anything) ** (integer) is (-1)**(integer)*(+anything**integer)
609
+ // Factoring -1 out:
610
+ // (negative anything ^ integer should be (-1 ^ integer) * (positive anything ^ integer))
611
+ & [ POS_ZERO , NEG_ZERO , POS_ONE , NEG_ONE , POS_EVENS , NEG_EVENS ] . iter ( ) . for_each ( |int_set| int_set. iter ( ) . for_each ( |int| {
612
+ test_sets ( ALL , & |v : f64 | pow ( -v, * int) , & |v : f64 | pow ( -1.0 , * int) * pow ( v, * int) ) ;
613
+ } ) ) ;
614
+
615
+ // / 23. (-anything except 0 and inf) ** (non-integer) is NAN
616
+ // Negative base (imaginary results):
617
+ // (-anything except 0 and Infinity ^ non-integer should be NAN)
618
+ & NEG [ 1 ..( NEG . len ( ) -1 ) ] . iter ( ) . for_each ( |set| set. iter ( ) . for_each ( |val| {
619
+ test_sets ( & ALL [ 3 ..7 ] , & |v : f64 | pow ( * val, v) , & |_| NAN ) ;
620
+ } ) ) ;
621
+
622
+ }
623
+
596
624
#[ test]
597
625
fn normal_cases ( ) {
598
626
assert_eq ! ( pow( 2.0 , 20.0 ) , ( 1 << 20 ) as f64 ) ;
599
627
assert_eq ! ( pow( -1.0 , 9.0 ) , -1.0 ) ;
600
628
assert ! ( pow( -1.0 , 2.2 ) . is_nan( ) ) ;
629
+ assert ! ( pow( -1.0 , -1.14 ) . is_nan( ) ) ;
601
630
}
602
631
}
0 commit comments