Skip to content

Commit d591a4f

Browse files
committed
---
yaml --- r: 59389 b: refs/heads/snap-stage3 c: 387d6c5 h: refs/heads/master i: 59387: d43cdfd v: v3
1 parent eede5b4 commit d591a4f

File tree

10 files changed

+97
-286
lines changed

10 files changed

+97
-286
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: c081ffbd1e845687202a975ea2e698b623e5722f
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: a9ac2b95f485c31e40273dee7f09dcfff8340777
4+
refs/heads/snap-stage3: 387d6c597aeb4d067998cb59f5526cee92994efa
55
refs/heads/try: c50a9d5b664478e533ba1d1d353213d70c8ad589
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libcore/num/cmath.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ pub mod c_double_utils {
3333
unsafe fn erf(n: c_double) -> c_double;
3434
unsafe fn erfc(n: c_double) -> c_double;
3535
unsafe fn exp(n: c_double) -> c_double;
36-
// rename: for consistency with underscore usage elsewhere
37-
#[link_name="expm1"] unsafe fn exp_m1(n: c_double) -> c_double;
36+
unsafe fn expm1(n: c_double) -> c_double;
3837
unsafe fn exp2(n: c_double) -> c_double;
3938
#[link_name="fabs"] unsafe fn abs(n: c_double) -> c_double;
4039
// rename: for clarity and consistency with add/sub/mul/div
@@ -64,7 +63,7 @@ pub mod c_double_utils {
6463
// renamed: "logb" /often/ is confused for log2 by beginners
6564
#[link_name="logb"] unsafe fn log_radix(n: c_double) -> c_double;
6665
// renamed: to be consitent with log as ln
67-
#[link_name="log1p"] unsafe fn ln_1p(n: c_double) -> c_double;
66+
#[link_name="log1p"] unsafe fn ln1p(n: c_double) -> c_double;
6867
unsafe fn log10(n: c_double) -> c_double;
6968
unsafe fn log2(n: c_double) -> c_double;
7069
#[link_name="ilogb"] unsafe fn ilog_radix(n: c_double) -> c_int;
@@ -118,7 +117,7 @@ pub mod c_float_utils {
118117
#[link_name="erff"] unsafe fn erf(n: c_float) -> c_float;
119118
#[link_name="erfcf"] unsafe fn erfc(n: c_float) -> c_float;
120119
#[link_name="expf"] unsafe fn exp(n: c_float) -> c_float;
121-
#[link_name="expm1f"]unsafe fn exp_m1(n: c_float) -> c_float;
120+
#[link_name="expm1f"]unsafe fn expm1(n: c_float) -> c_float;
122121
#[link_name="exp2f"] unsafe fn exp2(n: c_float) -> c_float;
123122
#[link_name="fabsf"] unsafe fn abs(n: c_float) -> c_float;
124123
#[link_name="fdimf"]
@@ -149,7 +148,7 @@ pub mod c_float_utils {
149148

150149
#[link_name="logf"] unsafe fn ln(n: c_float) -> c_float;
151150
#[link_name="logbf"] unsafe fn log_radix(n: c_float) -> c_float;
152-
#[link_name="log1pf"] unsafe fn ln_1p(n: c_float) -> c_float;
151+
#[link_name="log1pf"] unsafe fn ln1p(n: c_float) -> c_float;
153152
#[link_name="log2f"] unsafe fn log2(n: c_float) -> c_float;
154153
#[link_name="log10f"] unsafe fn log10(n: c_float) -> c_float;
155154
#[link_name="ilogbf"] unsafe fn ilog_radix(n: c_float) -> c_int;

branches/snap-stage3/src/libcore/num/f32.rs

Lines changed: 24 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ delegate!(
8282
fn cosh(n: c_float) -> c_float = c_float_utils::cosh,
8383
fn erf(n: c_float) -> c_float = c_float_utils::erf,
8484
fn erfc(n: c_float) -> c_float = c_float_utils::erfc,
85-
fn exp_m1(n: c_float) -> c_float = c_float_utils::exp_m1,
85+
fn expm1(n: c_float) -> c_float = c_float_utils::expm1,
8686
fn abs_sub(a: c_float, b: c_float) -> c_float = c_float_utils::abs_sub,
8787
fn fmax(a: c_float, b: c_float) -> c_float = c_float_utils::fmax,
8888
fn fmin(a: c_float, b: c_float) -> c_float = c_float_utils::fmin,
@@ -92,7 +92,7 @@ delegate!(
9292
fn ldexp(x: c_float, n: c_int) -> c_float = c_float_utils::ldexp,
9393
fn lgamma(n: c_float, sign: &mut c_int) -> c_float = c_float_utils::lgamma,
9494
fn log_radix(n: c_float) -> c_float = c_float_utils::log_radix,
95-
fn ln_1p(n: c_float) -> c_float = c_float_utils::ln_1p,
95+
fn ln1p(n: c_float) -> c_float = c_float_utils::ln1p,
9696
fn ilog_radix(n: c_float) -> c_int = c_float_utils::ilog_radix,
9797
fn modf(n: c_float, iptr: &mut c_float) -> c_float = c_float_utils::modf,
9898
fn round(n: c_float) -> c_float = c_float_utils::round,
@@ -195,6 +195,11 @@ pub mod consts {
195195
pub static ln_10: f32 = 2.30258509299404568401799145468436421_f32;
196196
}
197197

198+
#[inline(always)]
199+
pub fn logarithm(n: f32, b: f32) -> f32 {
200+
return log2(n) / log2(b);
201+
}
202+
198203
impl Num for f32 {}
199204

200205
#[cfg(notest)]
@@ -312,13 +317,6 @@ impl Signed for f32 {
312317
#[inline(always)]
313318
fn abs(&self) -> f32 { abs(*self) }
314319

315-
///
316-
/// The positive difference of two numbers. Returns `0.0` if the number is less than or
317-
/// equal to `other`, otherwise the difference between`self` and `other` is returned.
318-
///
319-
#[inline(always)]
320-
fn abs_sub(&self, other: &f32) -> f32 { abs_sub(*self, *other) }
321-
322320
///
323321
/// # Returns
324322
///
@@ -415,27 +413,21 @@ impl Trigonometric for f32 {
415413
}
416414

417415
impl Exponential for f32 {
418-
/// Returns the exponential of the number
419416
#[inline(always)]
420417
fn exp(&self) -> f32 { exp(*self) }
421418

422-
/// Returns 2 raised to the power of the number
423419
#[inline(always)]
424420
fn exp2(&self) -> f32 { exp2(*self) }
425421

426-
/// Returns the natural logarithm of the number
427422
#[inline(always)]
428-
fn ln(&self) -> f32 { ln(*self) }
423+
fn expm1(&self) -> f32 { expm1(*self) }
429424

430-
/// Returns the logarithm of the number with respect to an arbitrary base
431425
#[inline(always)]
432-
fn log(&self, base: f32) -> f32 { self.ln() / base.ln() }
426+
fn log(&self) -> f32 { ln(*self) }
433427

434-
/// Returns the base 2 logarithm of the number
435428
#[inline(always)]
436429
fn log2(&self) -> f32 { log2(*self) }
437430

438-
/// Returns the base 10 logarithm of the number
439431
#[inline(always)]
440432
fn log10(&self) -> f32 { log10(*self) }
441433
}
@@ -512,13 +504,13 @@ impl Real for f32 {
512504
#[inline(always)]
513505
fn log10_e() -> f32 { 0.434294481903251827651128918916605082 }
514506

515-
/// ln(2.0)
507+
/// log(2.0)
516508
#[inline(always)]
517-
fn ln_2() -> f32 { 0.693147180559945309417232121458176568 }
509+
fn log_2() -> f32 { 0.693147180559945309417232121458176568 }
518510

519-
/// ln(10.0)
511+
/// log(10.0)
520512
#[inline(always)]
521-
fn ln_10() -> f32 { 2.30258509299404568401799145468436421 }
513+
fn log_10() -> f32 { 2.30258509299404568401799145468436421 }
522514

523515
/// Converts to degrees, assuming the number is in radians
524516
#[inline(always)]
@@ -558,22 +550,9 @@ impl Float for f32 {
558550
#[inline(always)]
559551
fn neg_zero() -> f32 { -0.0 }
560552

561-
/// Returns `true` if the number is NaN
562553
#[inline(always)]
563554
fn is_NaN(&self) -> bool { *self != *self }
564555

565-
/// Returns `true` if the number is infinite
566-
#[inline(always)]
567-
fn is_infinite(&self) -> bool {
568-
*self == Float::infinity() || *self == Float::neg_infinity()
569-
}
570-
571-
/// Returns `true` if the number is not infinite or NaN
572-
#[inline(always)]
573-
fn is_finite(&self) -> bool {
574-
!(self.is_NaN() || self.is_infinite())
575-
}
576-
577556
#[inline(always)]
578557
fn mantissa_digits() -> uint { 24 }
579558

@@ -595,19 +574,17 @@ impl Float for f32 {
595574
#[inline(always)]
596575
fn max_10_exp() -> int { 38 }
597576

598-
///
599-
/// Returns the exponential of the number, minus `1`, in a way that is accurate
600-
/// even if the number is close to zero
601-
///
577+
/// Returns `true` if the number is infinite
602578
#[inline(always)]
603-
fn exp_m1(&self) -> f32 { exp_m1(*self) }
579+
fn is_infinite(&self) -> bool {
580+
*self == Float::infinity() || *self == Float::neg_infinity()
581+
}
604582

605-
///
606-
/// Returns the natural logarithm of the number plus `1` (`ln(1+n)`) more accurately
607-
/// than if the operations were performed separately
608-
///
583+
/// Returns `true` if the number is finite
609584
#[inline(always)]
610-
fn ln_1p(&self) -> f32 { ln_1p(*self) }
585+
fn is_finite(&self) -> bool {
586+
!(self.is_NaN() || self.is_infinite())
587+
}
611588

612589
///
613590
/// Fused multiply-add. Computes `(self * a) + b` with only one rounding error. This
@@ -961,12 +938,12 @@ mod tests {
961938
assert_approx_eq!(Real::frac_1_sqrt2::<f32>(), 1f32 / 2f32.sqrt());
962939
assert_approx_eq!(Real::log2_e::<f32>(), Real::e::<f32>().log2());
963940
assert_approx_eq!(Real::log10_e::<f32>(), Real::e::<f32>().log10());
964-
assert_approx_eq!(Real::ln_2::<f32>(), 2f32.ln());
965-
assert_approx_eq!(Real::ln_10::<f32>(), 10f32.ln());
941+
assert_approx_eq!(Real::log_2::<f32>(), 2f32.log());
942+
assert_approx_eq!(Real::log_10::<f32>(), 10f32.log());
966943
}
967944

968945
#[test]
969-
pub fn test_abs() {
946+
pub fn test_signed() {
970947
assert_eq!(infinity.abs(), infinity);
971948
assert_eq!(1f32.abs(), 1f32);
972949
assert_eq!(0f32.abs(), 0f32);
@@ -975,24 +952,7 @@ mod tests {
975952
assert_eq!(neg_infinity.abs(), infinity);
976953
assert_eq!((1f32/neg_infinity).abs(), 0f32);
977954
assert!(NaN.abs().is_NaN());
978-
}
979-
980-
#[test]
981-
fn test_abs_sub() {
982-
assert_eq!((-1f32).abs_sub(&1f32), 0f32);
983-
assert_eq!(1f32.abs_sub(&1f32), 0f32);
984-
assert_eq!(1f32.abs_sub(&0f32), 1f32);
985-
assert_eq!(1f32.abs_sub(&-1f32), 2f32);
986-
assert_eq!(neg_infinity.abs_sub(&0f32), 0f32);
987-
assert_eq!(infinity.abs_sub(&1f32), infinity);
988-
assert_eq!(0f32.abs_sub(&neg_infinity), infinity);
989-
assert_eq!(0f32.abs_sub(&infinity), 0f32);
990-
assert!(NaN.abs_sub(&-1f32).is_NaN());
991-
assert!(1f32.abs_sub(&NaN).is_NaN());
992-
}
993955

994-
#[test]
995-
fn test_signum() {
996956
assert_eq!(infinity.signum(), 1f32);
997957
assert_eq!(1f32.signum(), 1f32);
998958
assert_eq!(0f32.signum(), 1f32);
@@ -1001,10 +961,7 @@ mod tests {
1001961
assert_eq!(neg_infinity.signum(), -1f32);
1002962
assert_eq!((1f32/neg_infinity).signum(), -1f32);
1003963
assert!(NaN.signum().is_NaN());
1004-
}
1005964

1006-
#[test]
1007-
fn test_is_positive() {
1008965
assert!(infinity.is_positive());
1009966
assert!(1f32.is_positive());
1010967
assert!(0f32.is_positive());
@@ -1013,10 +970,7 @@ mod tests {
1013970
assert!(!neg_infinity.is_positive());
1014971
assert!(!(1f32/neg_infinity).is_positive());
1015972
assert!(!NaN.is_positive());
1016-
}
1017973

1018-
#[test]
1019-
fn test_is_negative() {
1020974
assert!(!infinity.is_negative());
1021975
assert!(!1f32.is_negative());
1022976
assert!(!0f32.is_negative());

0 commit comments

Comments
 (0)