@@ -387,15 +387,21 @@ pub fn tan(x: float) -> float {
387
387
388
388
#[cfg(notest)]
389
389
impl Eq for float {
390
+ #[inline(always)]
390
391
fn eq(&self, other: &float) -> bool { (*self) == (*other) }
392
+ #[inline(always)]
391
393
fn ne(&self, other: &float) -> bool { (*self) != (*other) }
392
394
}
393
395
394
396
#[cfg(notest)]
395
397
impl Ord for float {
398
+ #[inline(always)]
396
399
fn lt(&self, other: &float) -> bool { (*self) < (*other) }
400
+ #[inline(always)]
397
401
fn le(&self, other: &float) -> bool { (*self) <= (*other) }
402
+ #[inline(always)]
398
403
fn ge(&self, other: &float) -> bool { (*self) >= (*other) }
404
+ #[inline(always)]
399
405
fn gt(&self, other: &float) -> bool { (*self) > (*other) }
400
406
}
401
407
@@ -444,26 +450,32 @@ impl num::Round for float {
444
450
445
451
#[cfg(notest)]
446
452
impl ops::Add<float,float> for float {
453
+ #[inline(always)]
447
454
fn add(&self, other: &float) -> float { *self + *other }
448
455
}
449
456
#[cfg(notest)]
450
457
impl ops::Sub<float,float> for float {
458
+ #[inline(always)]
451
459
fn sub(&self, other: &float) -> float { *self - *other }
452
460
}
453
461
#[cfg(notest)]
454
462
impl ops::Mul<float,float> for float {
463
+ #[inline(always)]
455
464
fn mul(&self, other: &float) -> float { *self * *other }
456
465
}
457
466
#[cfg(notest)]
458
467
impl ops::Div<float,float> for float {
468
+ #[inline(always)]
459
469
fn div(&self, other: &float) -> float { *self / *other }
460
470
}
461
471
#[cfg(notest)]
462
472
impl ops::Modulo<float,float> for float {
473
+ #[inline(always)]
463
474
fn modulo(&self, other: &float) -> float { *self % *other }
464
475
}
465
476
#[cfg(notest)]
466
477
impl ops::Neg<float> for float {
478
+ #[inline(always)]
467
479
fn neg(&self) -> float { -*self }
468
480
}
469
481
@@ -474,29 +486,29 @@ mod tests {
474
486
#[test]
475
487
pub fn test_to_str_exact_do_decimal() {
476
488
let s = to_str_exact(5.0, 4u);
477
- assert !(s == ~" 5.0000 ");
489
+ assert_eq !(s, ~" 5.0000 ");
478
490
}
479
491
480
492
#[test]
481
493
pub fn test_from_str() {
482
- assert !(from_str(~" 3 ") == Some(3.));
483
- assert !(from_str(~" 3.14 ") == Some(3.14));
484
- assert !(from_str(~" +3.14 ") == Some(3.14));
485
- assert !(from_str(~" -3.14 ") == Some(-3.14));
486
- assert !(from_str(~" 2.5E10 ") == Some(25000000000.));
487
- assert !(from_str(~" 2.5e10 ") == Some(25000000000.));
488
- assert !(from_str(~" 25000000000 . E -10 ") == Some(2.5));
489
- assert !(from_str(~" . ") == Some(0.));
490
- assert !(from_str(~" . e1") == Some(0.));
491
- assert !(from_str(~" . e-1 ") == Some(0.));
492
- assert !(from_str(~" 5. ") == Some(5.));
493
- assert !(from_str(~" . 5 ") == Some(0.5));
494
- assert !(from_str(~" 0.5 ") == Some(0.5));
495
- assert !(from_str(~" -. 5 ") == Some(-0.5));
496
- assert !(from_str(~" -5 ") == Some(-5.));
497
- assert !(from_str(~" inf") == Some(infinity));
498
- assert !(from_str(~" +inf") == Some(infinity));
499
- assert !(from_str(~" -inf") == Some(neg_infinity));
494
+ assert_eq !(from_str(~" 3 "), Some(3.));
495
+ assert_eq !(from_str(~" 3.14 "), Some(3.14));
496
+ assert_eq !(from_str(~" +3.14 "), Some(3.14));
497
+ assert_eq !(from_str(~" -3.14 "), Some(-3.14));
498
+ assert_eq !(from_str(~" 2.5E10 "), Some(25000000000.));
499
+ assert_eq !(from_str(~" 2.5e10 "), Some(25000000000.));
500
+ assert_eq !(from_str(~" 25000000000 . E -10 "), Some(2.5));
501
+ assert_eq !(from_str(~" . "), Some(0.));
502
+ assert_eq !(from_str(~" . e1"), Some(0.));
503
+ assert_eq !(from_str(~" . e-1 "), Some(0.));
504
+ assert_eq !(from_str(~" 5. "), Some(5.));
505
+ assert_eq !(from_str(~" . 5 "), Some(0.5));
506
+ assert_eq !(from_str(~" 0.5 "), Some(0.5));
507
+ assert_eq !(from_str(~" -. 5 "), Some(-0.5));
508
+ assert_eq !(from_str(~" -5 "), Some(-5.));
509
+ assert_eq !(from_str(~" inf"), Some(infinity));
510
+ assert_eq !(from_str(~" +inf"), Some(infinity));
511
+ assert_eq !(from_str(~" -inf"), Some(neg_infinity));
500
512
// note: NaN != NaN, hence this slightly complex test
501
513
match from_str(~" NaN ") {
502
514
Some(f) => assert!(is_NaN(f)),
@@ -526,24 +538,24 @@ mod tests {
526
538
527
539
#[test]
528
540
pub fn test_from_str_hex() {
529
- assert !(from_str_hex(~" a4") == Some(164.));
530
- assert !(from_str_hex(~" a4. fe") == Some(164.9921875));
531
- assert !(from_str_hex(~" -a4. fe") == Some(-164.9921875));
532
- assert !(from_str_hex(~" +a4. fe") == Some(164.9921875));
533
- assert !(from_str_hex(~" ff0P4") == Some(0xff00 as float));
534
- assert !(from_str_hex(~" ff0p4") == Some(0xff00 as float));
535
- assert !(from_str_hex(~" ff0p-4 ") == Some(0xff as float));
536
- assert !(from_str_hex(~" . ") == Some(0.));
537
- assert !(from_str_hex(~" . p1") == Some(0.));
538
- assert !(from_str_hex(~" . p-1 ") == Some(0.));
539
- assert !(from_str_hex(~" f. ") == Some(15.));
540
- assert !(from_str_hex(~" . f") == Some(0.9375));
541
- assert !(from_str_hex(~" 0 . f") == Some(0.9375));
542
- assert !(from_str_hex(~" -. f") == Some(-0.9375));
543
- assert !(from_str_hex(~" -f") == Some(-15.));
544
- assert !(from_str_hex(~" inf") == Some(infinity));
545
- assert !(from_str_hex(~" +inf") == Some(infinity));
546
- assert !(from_str_hex(~" -inf") == Some(neg_infinity));
541
+ assert_eq !(from_str_hex(~" a4"), Some(164.));
542
+ assert_eq !(from_str_hex(~" a4. fe"), Some(164.9921875));
543
+ assert_eq !(from_str_hex(~" -a4. fe"), Some(-164.9921875));
544
+ assert_eq !(from_str_hex(~" +a4. fe"), Some(164.9921875));
545
+ assert_eq !(from_str_hex(~" ff0P4"), Some(0xff00 as float));
546
+ assert_eq !(from_str_hex(~" ff0p4"), Some(0xff00 as float));
547
+ assert_eq !(from_str_hex(~" ff0p-4 "), Some(0xff as float));
548
+ assert_eq !(from_str_hex(~" . "), Some(0.));
549
+ assert_eq !(from_str_hex(~" . p1"), Some(0.));
550
+ assert_eq !(from_str_hex(~" . p-1 "), Some(0.));
551
+ assert_eq !(from_str_hex(~" f. "), Some(15.));
552
+ assert_eq !(from_str_hex(~" . f"), Some(0.9375));
553
+ assert_eq !(from_str_hex(~" 0 . f"), Some(0.9375));
554
+ assert_eq !(from_str_hex(~" -. f"), Some(-0.9375));
555
+ assert_eq !(from_str_hex(~" -f"), Some(-15.));
556
+ assert_eq !(from_str_hex(~" inf"), Some(infinity));
557
+ assert_eq !(from_str_hex(~" +inf"), Some(infinity));
558
+ assert_eq !(from_str_hex(~" -inf"), Some(neg_infinity));
547
559
// note: NaN != NaN, hence this slightly complex test
548
560
match from_str_hex(~" NaN ") {
549
561
Some(f) => assert!(is_NaN(f)),
@@ -558,11 +570,11 @@ mod tests {
558
570
Some(v) if is_zero(v) => assert!(is_positive(v)),
559
571
_ => fail!()
560
572
}
561
- assert !(from_str_hex(~" e") == Some(14.));
562
- assert !(from_str_hex(~" E ") == Some(14.));
563
- assert !(from_str_hex(~" E1 ") == Some(225.));
564
- assert !(from_str_hex(~" 1e1 e1") == Some(123361.));
565
- assert !(from_str_hex(~" 1e1 . 1 ") == Some(481.0625));
573
+ assert_eq !(from_str_hex(~" e"), Some(14.));
574
+ assert_eq !(from_str_hex(~" E "), Some(14.));
575
+ assert_eq !(from_str_hex(~" E1 "), Some(225.));
576
+ assert_eq !(from_str_hex(~" 1e1 e1"), Some(123361.));
577
+ assert_eq !(from_str_hex(~" 1e1 . 1 "), Some(481.0625));
566
578
567
579
assert!(from_str_hex(~" ").is_none());
568
580
assert!(from_str_hex(~" x").is_none());
@@ -578,92 +590,92 @@ mod tests {
578
590
579
591
#[test]
580
592
pub fn test_to_str_hex() {
581
- assert !(to_str_hex(164.) == ~" a4");
582
- assert !(to_str_hex(164.9921875) == ~" a4. fe");
583
- assert !(to_str_hex(-164.9921875) == ~" -a4. fe");
584
- assert !(to_str_hex(0xff00 as float) == ~" ff00");
585
- assert !(to_str_hex(-(0xff00 as float)) == ~" -ff00");
586
- assert !(to_str_hex(0.) == ~" 0 ");
587
- assert !(to_str_hex(15.) == ~" f");
588
- assert !(to_str_hex(-15.) == ~" -f");
589
- assert !(to_str_hex(0.9375) == ~" 0 . f");
590
- assert !(to_str_hex(-0.9375) == ~" -0 . f");
591
- assert !(to_str_hex(infinity) == ~" inf");
592
- assert !(to_str_hex(neg_infinity) == ~" -inf");
593
- assert !(to_str_hex(NaN) == ~" NaN ");
594
- assert !(to_str_hex(0.) == ~" 0 ");
595
- assert !(to_str_hex(-0.) == ~" -0 ");
593
+ assert_eq !(to_str_hex(164.), ~" a4");
594
+ assert_eq !(to_str_hex(164.9921875), ~" a4. fe");
595
+ assert_eq !(to_str_hex(-164.9921875), ~" -a4. fe");
596
+ assert_eq !(to_str_hex(0xff00 as float), ~" ff00");
597
+ assert_eq !(to_str_hex(-(0xff00 as float)), ~" -ff00");
598
+ assert_eq !(to_str_hex(0.), ~" 0 ");
599
+ assert_eq !(to_str_hex(15.), ~" f");
600
+ assert_eq !(to_str_hex(-15.), ~" -f");
601
+ assert_eq !(to_str_hex(0.9375), ~" 0 . f");
602
+ assert_eq !(to_str_hex(-0.9375), ~" -0 . f");
603
+ assert_eq !(to_str_hex(infinity), ~" inf");
604
+ assert_eq !(to_str_hex(neg_infinity), ~" -inf");
605
+ assert_eq !(to_str_hex(NaN), ~" NaN ");
606
+ assert_eq !(to_str_hex(0.), ~" 0 ");
607
+ assert_eq !(to_str_hex(-0.), ~" -0 ");
596
608
}
597
609
598
610
#[test]
599
611
pub fn test_to_str_radix() {
600
- assert !(to_str_radix(36., 36u) == ~" 10 ");
601
- assert !(to_str_radix(8.125, 2u) == ~" 1000.001 ");
612
+ assert_eq !(to_str_radix(36., 36u), ~" 10 ");
613
+ assert_eq !(to_str_radix(8.125, 2u), ~" 1000.001 ");
602
614
}
603
615
604
616
#[test]
605
617
pub fn test_from_str_radix() {
606
- assert !(from_str_radix(~" 10 ", 36u) == Some(36.));
607
- assert !(from_str_radix(~" 1000.001 ", 2u) == Some(8.125));
618
+ assert_eq !(from_str_radix(~" 10 ", 36u), Some(36.));
619
+ assert_eq !(from_str_radix(~" 1000.001 ", 2u), Some(8.125));
608
620
}
609
621
610
622
#[test]
611
623
pub fn test_positive() {
612
- assert!(( is_positive(infinity) ));
613
- assert!(( is_positive(1.) ));
614
- assert!(( is_positive(0.) ));
615
- assert!(( !is_positive(-1.) ));
616
- assert!(( !is_positive(neg_infinity) ));
617
- assert!(( !is_positive(1./neg_infinity) ));
618
- assert!(( !is_positive(NaN) ));
624
+ assert!(is_positive(infinity));
625
+ assert!(is_positive(1.));
626
+ assert!(is_positive(0.));
627
+ assert!(!is_positive(-1.));
628
+ assert!(!is_positive(neg_infinity));
629
+ assert!(!is_positive(1./neg_infinity));
630
+ assert!(!is_positive(NaN));
619
631
}
620
632
621
633
#[test]
622
634
pub fn test_negative() {
623
- assert!(( !is_negative(infinity) ));
624
- assert!(( !is_negative(1.) ));
625
- assert!(( !is_negative(0.) ));
626
- assert!(( is_negative(-1.) ));
627
- assert!(( is_negative(neg_infinity) ));
628
- assert!(( is_negative(1./neg_infinity) ));
629
- assert!(( !is_negative(NaN) ));
635
+ assert!(!is_negative(infinity));
636
+ assert!(!is_negative(1.));
637
+ assert!(!is_negative(0.));
638
+ assert!(is_negative(-1.));
639
+ assert!(is_negative(neg_infinity));
640
+ assert!(is_negative(1./neg_infinity));
641
+ assert!(!is_negative(NaN));
630
642
}
631
643
632
644
#[test]
633
645
pub fn test_nonpositive() {
634
- assert!(( !is_nonpositive(infinity) ));
635
- assert!(( !is_nonpositive(1.) ));
636
- assert!(( !is_nonpositive(0.) ));
637
- assert!(( is_nonpositive(-1.) ));
638
- assert!(( is_nonpositive(neg_infinity) ));
639
- assert!(( is_nonpositive(1./neg_infinity) ));
640
- assert!(( !is_nonpositive(NaN) ));
646
+ assert!(!is_nonpositive(infinity));
647
+ assert!(!is_nonpositive(1.));
648
+ assert!(!is_nonpositive(0.));
649
+ assert!(is_nonpositive(-1.));
650
+ assert!(is_nonpositive(neg_infinity));
651
+ assert!(is_nonpositive(1./neg_infinity));
652
+ assert!(!is_nonpositive(NaN));
641
653
}
642
654
643
655
#[test]
644
656
pub fn test_nonnegative() {
645
- assert!(( is_nonnegative(infinity) ));
646
- assert!(( is_nonnegative(1.) ));
647
- assert!(( is_nonnegative(0.) ));
648
- assert!(( !is_nonnegative(-1.) ));
649
- assert!(( !is_nonnegative(neg_infinity) ));
650
- assert!(( !is_nonnegative(1./neg_infinity) ));
651
- assert!(( !is_nonnegative(NaN) ));
657
+ assert!(is_nonnegative(infinity));
658
+ assert!(is_nonnegative(1.));
659
+ assert!(is_nonnegative(0.));
660
+ assert!(!is_nonnegative(-1.));
661
+ assert!(!is_nonnegative(neg_infinity));
662
+ assert!(!is_nonnegative(1./neg_infinity));
663
+ assert!(!is_nonnegative(NaN));
652
664
}
653
665
654
666
#[test]
655
667
pub fn test_to_str_inf() {
656
- assert !(to_str_digits(infinity, 10u) == ~" inf");
657
- assert !(to_str_digits(-infinity, 10u) == ~" -inf" ) ;
668
+ assert_eq !(to_str_digits(infinity, 10u), ~" inf");
669
+ assert_eq !(to_str_digits(-infinity, 10u), ~" -inf" ) ;
658
670
}
659
671
660
672
#[ test]
661
673
pub fn test_round ( ) {
662
- assert ! ( round( 5.8 ) == 6.0 ) ;
663
- assert ! ( round( 5.2 ) == 5.0 ) ;
664
- assert ! ( round( 3.0 ) == 3.0 ) ;
665
- assert ! ( round( 2.5 ) == 3.0 ) ;
666
- assert ! ( round( -3.5 ) == -4.0 ) ;
674
+ assert_eq ! ( round( 5.8 ) , 6.0 ) ;
675
+ assert_eq ! ( round( 5.2 ) , 5.0 ) ;
676
+ assert_eq ! ( round( 3.0 ) , 3.0 ) ;
677
+ assert_eq ! ( round( 2.5 ) , 3.0 ) ;
678
+ assert_eq ! ( round( -3.5 ) , -4.0 ) ;
667
679
}
668
680
}
669
681
0 commit comments