Skip to content

Commit 8796c9f

Browse files
committed
auto merge of #5935 : bjz/rust/master, r=thestinger
2 parents e4f35a7 + a7f6ec8 commit 8796c9f

File tree

6 files changed

+367
-255
lines changed

6 files changed

+367
-255
lines changed

src/libcore/num/f32.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,26 +288,32 @@ impl num::One for f32 {
288288

289289
#[cfg(notest)]
290290
impl ops::Add<f32,f32> for f32 {
291+
#[inline(always)]
291292
fn add(&self, other: &f32) -> f32 { *self + *other }
292293
}
293294
#[cfg(notest)]
294295
impl ops::Sub<f32,f32> for f32 {
296+
#[inline(always)]
295297
fn sub(&self, other: &f32) -> f32 { *self - *other }
296298
}
297299
#[cfg(notest)]
298300
impl ops::Mul<f32,f32> for f32 {
301+
#[inline(always)]
299302
fn mul(&self, other: &f32) -> f32 { *self * *other }
300303
}
301304
#[cfg(notest)]
302305
impl ops::Div<f32,f32> for f32 {
306+
#[inline(always)]
303307
fn div(&self, other: &f32) -> f32 { *self / *other }
304308
}
305309
#[cfg(notest)]
306310
impl ops::Modulo<f32,f32> for f32 {
311+
#[inline(always)]
307312
fn modulo(&self, other: &f32) -> f32 { *self % *other }
308313
}
309314
#[cfg(notest)]
310315
impl ops::Neg<f32> for f32 {
316+
#[inline(always)]
311317
fn neg(&self) -> f32 { -*self }
312318
}
313319

src/libcore/num/f64.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,26 +310,32 @@ impl num::One for f64 {
310310

311311
#[cfg(notest)]
312312
impl ops::Add<f64,f64> for f64 {
313+
#[inline(always)]
313314
fn add(&self, other: &f64) -> f64 { *self + *other }
314315
}
315316
#[cfg(notest)]
316317
impl ops::Sub<f64,f64> for f64 {
318+
#[inline(always)]
317319
fn sub(&self, other: &f64) -> f64 { *self - *other }
318320
}
319321
#[cfg(notest)]
320322
impl ops::Mul<f64,f64> for f64 {
323+
#[inline(always)]
321324
fn mul(&self, other: &f64) -> f64 { *self * *other }
322325
}
323326
#[cfg(notest)]
324327
impl ops::Div<f64,f64> for f64 {
328+
#[inline(always)]
325329
fn div(&self, other: &f64) -> f64 { *self / *other }
326330
}
327331
#[cfg(notest)]
328332
impl ops::Modulo<f64,f64> for f64 {
333+
#[inline(always)]
329334
fn modulo(&self, other: &f64) -> f64 { *self % *other }
330335
}
331336
#[cfg(notest)]
332337
impl ops::Neg<f64> for f64 {
338+
#[inline(always)]
333339
fn neg(&self) -> f64 { -*self }
334340
}
335341

src/libcore/num/float.rs

Lines changed: 108 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -387,15 +387,21 @@ pub fn tan(x: float) -> float {
387387
388388
#[cfg(notest)]
389389
impl Eq for float {
390+
#[inline(always)]
390391
fn eq(&self, other: &float) -> bool { (*self) == (*other) }
392+
#[inline(always)]
391393
fn ne(&self, other: &float) -> bool { (*self) != (*other) }
392394
}
393395
394396
#[cfg(notest)]
395397
impl Ord for float {
398+
#[inline(always)]
396399
fn lt(&self, other: &float) -> bool { (*self) < (*other) }
400+
#[inline(always)]
397401
fn le(&self, other: &float) -> bool { (*self) <= (*other) }
402+
#[inline(always)]
398403
fn ge(&self, other: &float) -> bool { (*self) >= (*other) }
404+
#[inline(always)]
399405
fn gt(&self, other: &float) -> bool { (*self) > (*other) }
400406
}
401407
@@ -444,26 +450,32 @@ impl num::Round for float {
444450
445451
#[cfg(notest)]
446452
impl ops::Add<float,float> for float {
453+
#[inline(always)]
447454
fn add(&self, other: &float) -> float { *self + *other }
448455
}
449456
#[cfg(notest)]
450457
impl ops::Sub<float,float> for float {
458+
#[inline(always)]
451459
fn sub(&self, other: &float) -> float { *self - *other }
452460
}
453461
#[cfg(notest)]
454462
impl ops::Mul<float,float> for float {
463+
#[inline(always)]
455464
fn mul(&self, other: &float) -> float { *self * *other }
456465
}
457466
#[cfg(notest)]
458467
impl ops::Div<float,float> for float {
468+
#[inline(always)]
459469
fn div(&self, other: &float) -> float { *self / *other }
460470
}
461471
#[cfg(notest)]
462472
impl ops::Modulo<float,float> for float {
473+
#[inline(always)]
463474
fn modulo(&self, other: &float) -> float { *self % *other }
464475
}
465476
#[cfg(notest)]
466477
impl ops::Neg<float> for float {
478+
#[inline(always)]
467479
fn neg(&self) -> float { -*self }
468480
}
469481
@@ -474,29 +486,29 @@ mod tests {
474486
#[test]
475487
pub fn test_to_str_exact_do_decimal() {
476488
let s = to_str_exact(5.0, 4u);
477-
assert!(s == ~"5.0000");
489+
assert_eq!(s, ~"5.0000");
478490
}
479491
480492
#[test]
481493
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));
500512
// note: NaN != NaN, hence this slightly complex test
501513
match from_str(~"NaN") {
502514
Some(f) => assert!(is_NaN(f)),
@@ -526,24 +538,24 @@ mod tests {
526538
527539
#[test]
528540
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));
547559
// note: NaN != NaN, hence this slightly complex test
548560
match from_str_hex(~"NaN") {
549561
Some(f) => assert!(is_NaN(f)),
@@ -558,11 +570,11 @@ mod tests {
558570
Some(v) if is_zero(v) => assert!(is_positive(v)),
559571
_ => fail!()
560572
}
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(~"1e1e1") == 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(~"1e1e1"), Some(123361.));
577+
assert_eq!(from_str_hex(~"1e1.1"), Some(481.0625));
566578
567579
assert!(from_str_hex(~"").is_none());
568580
assert!(from_str_hex(~"x").is_none());
@@ -578,92 +590,92 @@ mod tests {
578590
579591
#[test]
580592
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");
596608
}
597609
598610
#[test]
599611
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");
602614
}
603615
604616
#[test]
605617
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));
608620
}
609621
610622
#[test]
611623
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));
619631
}
620632
621633
#[test]
622634
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));
630642
}
631643
632644
#[test]
633645
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));
641653
}
642654
643655
#[test]
644656
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));
652664
}
653665
654666
#[test]
655667
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");
658670
}
659671

660672
#[test]
661673
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);
667679
}
668680
}
669681

0 commit comments

Comments
 (0)