From c24fb126e7cdd73163af67c264bf626aebbeee84 Mon Sep 17 00:00:00 2001 From: "Артём Павлов [Artyom Pavlov]" Date: Sun, 29 Jul 2018 07:00:13 +0300 Subject: duration div mul extras --- src/libstd/time.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/libstd') diff --git a/src/libstd/time.rs b/src/libstd/time.rs index 90ab3491599..640902426cd 100644 --- a/src/libstd/time.rs +++ b/src/libstd/time.rs @@ -590,4 +590,30 @@ mod tests { let hundred_twenty_years = thirty_years * 4; assert!(a < hundred_twenty_years); } + + #[test] + fn duration_float_ops() { + let dur = Duration::new(2, 700_000_000); + + let dur2 = 3.14*dur; + assert_eq!(dur2, dur*3.14); + assert_eq!(dur2.as_secs(), 8); + assert_eq!(dur2.subsec_nanos(), 478_000_000); + + let dur3 = 3.14e5*dur; + assert_eq!(dur3, dur*3.14e5); + assert_eq!(dur3.as_secs(), 847_800); + assert_eq!(dur3.subsec_nanos(), 0); + + let dur4 = dur/3.14; + assert_eq!(dur4.as_secs(), 0); + assert_eq!(dur4.subsec_nanos(), 859_872_611); + + let dur5 = dur/3.14e5; + assert_eq!(dur5.as_secs(), 0); + // we are using truncation and not rounding + assert_eq!(dur5.subsec_nanos(), 8598); + + assert_eq!(dur/Duration::new(5, 400_000_000), 0.5); + } } -- cgit 1.4.1-3-g733a5 From 36dff2a5dec66d783ca575495c7af051f2d7de0c Mon Sep 17 00:00:00 2001 From: Artyom Pavlov Date: Wed, 12 Sep 2018 11:51:33 +0300 Subject: Remove tests --- src/libstd/time.rs | 26 -------------------------- 1 file changed, 26 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/time.rs b/src/libstd/time.rs index 640902426cd..90ab3491599 100644 --- a/src/libstd/time.rs +++ b/src/libstd/time.rs @@ -590,30 +590,4 @@ mod tests { let hundred_twenty_years = thirty_years * 4; assert!(a < hundred_twenty_years); } - - #[test] - fn duration_float_ops() { - let dur = Duration::new(2, 700_000_000); - - let dur2 = 3.14*dur; - assert_eq!(dur2, dur*3.14); - assert_eq!(dur2.as_secs(), 8); - assert_eq!(dur2.subsec_nanos(), 478_000_000); - - let dur3 = 3.14e5*dur; - assert_eq!(dur3, dur*3.14e5); - assert_eq!(dur3.as_secs(), 847_800); - assert_eq!(dur3.subsec_nanos(), 0); - - let dur4 = dur/3.14; - assert_eq!(dur4.as_secs(), 0); - assert_eq!(dur4.subsec_nanos(), 859_872_611); - - let dur5 = dur/3.14e5; - assert_eq!(dur5.as_secs(), 0); - // we are using truncation and not rounding - assert_eq!(dur5.subsec_nanos(), 8598); - - assert_eq!(dur/Duration::new(5, 400_000_000), 0.5); - } } -- cgit 1.4.1-3-g733a5 From b74215accedd26b57907d3473fa325861b8a2f92 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sat, 15 Sep 2018 09:14:10 -0700 Subject: Switch wasm math symbols to their original names The names `Math_*` were given to help undefined symbol messages indicate how to implement them, but these are all implemented in compiler-rt now so there's no need to rename them! This change should make it so wasm binaries by default, no matter the math symbols used, will not have unresolved symbols. --- src/libstd/sys/wasm/cmath.rs | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/sys/wasm/cmath.rs b/src/libstd/sys/wasm/cmath.rs index 87ac2091cad..64fc14d42d9 100644 --- a/src/libstd/sys/wasm/cmath.rs +++ b/src/libstd/sys/wasm/cmath.rs @@ -74,46 +74,19 @@ pub unsafe fn tanhf(n: f32) -> f32 { f64::tanh(n as f64) as f32 } -// Right now all these functions, the f64 version of the functions above, all -// shell out to random names. These names aren't actually defined anywhere, per -// se, but we need this to compile somehow. -// -// The idea with this is that when you're using wasm then, for now, we have no -// way of providing an implementation of these which delegates to a "correct" -// implementation. For example most wasm applications probably just want to -// delegate to the javascript `Math` object and its related functions, but wasm -// doesn't currently have the ability to seamlessly do that (when you -// instantiate a module you have to set that up). -// -// As a result these are just defined here with "hopefully helpful" names. The -// symbols won't ever be needed or show up unless these functions are called, -// and hopefully when they're called the errors are self-explanatory enough to -// figure out what's going on. - +// These symbols are all defined in `compiler-builtins` extern { - #[link_name = "Math_acos"] pub fn acos(n: f64) -> f64; - #[link_name = "Math_asin"] pub fn asin(n: f64) -> f64; - #[link_name = "Math_atan"] pub fn atan(n: f64) -> f64; - #[link_name = "Math_atan2"] pub fn atan2(a: f64, b: f64) -> f64; - #[link_name = "Math_cbrt"] pub fn cbrt(n: f64) -> f64; - #[link_name = "Math_cosh"] pub fn cosh(n: f64) -> f64; - #[link_name = "Math_expm1"] pub fn expm1(n: f64) -> f64; pub fn fdim(a: f64, b: f64) -> f64; - #[link_name = "Math_log1p"] pub fn log1p(n: f64) -> f64; - #[link_name = "Math_sinh"] pub fn sinh(n: f64) -> f64; - #[link_name = "Math_tan"] pub fn tan(n: f64) -> f64; - #[link_name = "Math_tanh"] pub fn tanh(n: f64) -> f64; - #[link_name = "Math_hypot"] pub fn hypot(x: f64, y: f64) -> f64; } -- cgit 1.4.1-3-g733a5