Skip to content

Commit

Permalink
Rust1.63.0 hypotenuse__
Browse files Browse the repository at this point in the history
  • Loading branch information
YoungHaKim7 committed Aug 17, 2022
1 parent 26518ae commit 0b51c00
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
pub trait Hypot<T> {
fn hypot(self, b: T) -> f64;
}

impl<T> Hypot<T> for T
pub fn hypot<T>(a: T, b: T) -> f64
where
T: core::ops::Mul<T, Output = T>
+ core::ops::Add<T, Output = T>
+ core::convert::Into<f64>
+ Copy,
{
fn hypot(self, b: T) -> f64 {
(self * self + b * b).into().sqrt()
}
(a * a + b * b).into().sqrt()
}

fn main() {
let x = 3.0_f64;
let y = 4.0_f64;
let c = x.hypot(y);

println!("hypo : {c}");
println!("hypot : {c}");
}

0 comments on commit 0b51c00

Please sign in to comment.