File tree 4 files changed +46
-3
lines changed
4 files changed +46
-3
lines changed Original file line number Diff line number Diff line change @@ -88,7 +88,6 @@ pub trait F32Ext {
88
88
#[ cfg( todo) ]
89
89
fn cbrt ( self ) -> Self ;
90
90
91
- #[ cfg( todo) ]
92
91
fn hypot ( self , other : Self ) -> Self ;
93
92
94
93
#[ cfg( todo) ]
@@ -254,7 +253,6 @@ impl F32Ext for f32 {
254
253
cbrtf ( self )
255
254
}
256
255
257
- #[ cfg( todo) ]
258
256
#[ inline]
259
257
fn hypot ( self , other : Self ) -> Self {
260
258
hypotf ( self , other)
Original file line number Diff line number Diff line change
1
+ use core:: f32;
2
+
3
+ use super :: sqrtf;
4
+
5
+ #[ inline]
6
+ pub fn hypotf ( mut x : f32 , mut y : f32 ) -> f32 {
7
+ let x1p90 = f32:: from_bits ( 0x6c800000 ) ; // 0x1p90f === 2 ^ 90
8
+ let x1p_90 = f32:: from_bits ( 0x12800000 ) ; // 0x1p-90f === 2 ^ -90
9
+
10
+ let mut uxi = x. to_bits ( ) ;
11
+ let mut uyi = y. to_bits ( ) ;
12
+ let uti;
13
+ let mut z: f32 ;
14
+
15
+ uxi &= -1i32 as u32 >> 1 ;
16
+ uyi &= -1i32 as u32 >> 1 ;
17
+ if uxi < uyi {
18
+ uti = uxi;
19
+ uxi = uyi;
20
+ uyi = uti;
21
+ }
22
+
23
+ x = f32:: from_bits ( uxi) ;
24
+ y = f32:: from_bits ( uyi) ;
25
+ if uyi == 0xff <<23 {
26
+ return y;
27
+ }
28
+ if uxi >= 0xff <<23 || uyi == 0 || uxi - uyi >= 25 <<23 {
29
+ return x + y;
30
+ }
31
+
32
+ z = 1. ;
33
+ if uxi >= ( 0x7f +60 ) <<23 {
34
+ z = x1p90;
35
+ x *= x1p_90;
36
+ y *= x1p_90;
37
+ } else if uyi < ( 0x7f -60 ) <<23 {
38
+ z = x1p_90;
39
+ x *= x1p90;
40
+ y *= x1p90;
41
+ }
42
+ z* sqrtf ( ( x as f64 * x as f64 + y as f64 * y as f64 ) as f32 )
43
+ }
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ mod expf;
17
17
mod floor;
18
18
mod trunc;
19
19
mod truncf;
20
+ mod hypotf;
20
21
21
22
//mod service;
22
23
@@ -34,6 +35,7 @@ pub use self::{
34
35
floor:: floor,
35
36
trunc:: trunc,
36
37
truncf:: truncf,
38
+ hypotf:: hypotf,
37
39
} ;
38
40
39
41
fn isnanf ( x : f32 ) -> bool {
Original file line number Diff line number Diff line change @@ -678,7 +678,7 @@ f32_f32! {
678
678
// With signature `fn(f32, f32) -> f32`
679
679
f32f32_f32 ! {
680
680
// atan2f,
681
- // hypotf,
681
+ hypotf,
682
682
fmodf,
683
683
powf,
684
684
}
You can’t perform that action at this time.
0 commit comments