File tree 5 files changed +65
-6
lines changed 5 files changed +65
-6
lines changed Original file line number Diff line number Diff line change @@ -34,10 +34,8 @@ pub fn _eq(a: u64, b: u64) -> bool {
34
34
///
35
35
/// This trait is sealed and cannot be implemented outside of `libm`.
36
36
pub trait F32Ext : private:: Sealed {
37
- #[ cfg( todo) ]
38
37
fn floor ( self ) -> Self ;
39
38
40
- #[ cfg( todo) ]
41
39
fn ceil ( self ) -> Self ;
42
40
43
41
#[ cfg( todo) ]
@@ -142,13 +140,11 @@ pub trait F32Ext: private::Sealed {
142
140
}
143
141
144
142
impl F32Ext for f32 {
145
- #[ cfg( todo) ]
146
143
#[ inline]
147
144
fn floor ( self ) -> Self {
148
145
floorf ( self )
149
146
}
150
147
151
- #[ cfg( todo) ]
152
148
#[ inline]
153
149
fn ceil ( self ) -> Self {
154
150
ceilf ( self )
Original file line number Diff line number Diff line change
1
+ use core:: f32;
2
+
3
+ pub fn ceilf ( x : f32 ) -> f32 {
4
+ let mut ui = x. to_bits ( ) ;
5
+ let e = ( ( ( ui >> 23 ) & 0xff ) - 0x7f ) as i32 ;
6
+
7
+ if e >= 23 {
8
+ return x;
9
+ }
10
+ if e >= 0 {
11
+ let m = 0x007fffff >> e;
12
+ if ( ui & m) == 0 {
13
+ return x;
14
+ }
15
+ force_eval ! ( x + f32 :: from_bits( 0x7b800000 ) ) ;
16
+ if ui >> 31 == 0 {
17
+ ui += m;
18
+ }
19
+ ui &= !m;
20
+ } else {
21
+ force_eval ! ( x + f32 :: from_bits( 0x7b800000 ) ) ;
22
+ if ui >> 31 != 0 {
23
+ return -0.0 ;
24
+ } else if ui << 1 != 0 {
25
+ return 1.0 ;
26
+ }
27
+ }
28
+ return f32:: from_bits ( ui) ;
29
+ }
Original file line number Diff line number Diff line change
1
+ use core:: f32;
2
+
3
+ #[ inline]
4
+ pub fn floorf ( x : f32 ) -> f32 {
5
+ let mut ui = x. to_bits ( ) ;
6
+ let e = ( ( ( ui >> 23 ) & 0xff ) - 0x7f ) as i32 ;
7
+
8
+ if e >= 23 {
9
+ return x;
10
+ }
11
+ if e >= 0 {
12
+ let m: u32 = 0x007fffff >> e;
13
+ if ( ui & m) == 0 {
14
+ return x;
15
+ }
16
+ force_eval ! ( x + f32 :: from_bits( 0x7b800000 ) ) ;
17
+ if ui >> 31 != 0 {
18
+ ui += m;
19
+ }
20
+ ui &= !m;
21
+ } else {
22
+ force_eval ! ( x + f32 :: from_bits( 0x7b800000 ) ) ;
23
+ if ui >> 31 == 0 {
24
+ ui = 0 ;
25
+ } else if ui << 1 != 0 {
26
+ return -1.0 ;
27
+ }
28
+ }
29
+ return f32:: from_bits ( ui) ;
30
+ }
Original file line number Diff line number Diff line change @@ -4,8 +4,10 @@ macro_rules! force_eval {
4
4
}
5
5
}
6
6
7
+ mod ceilf;
7
8
mod fabs;
8
9
mod fabsf;
10
+ mod floorf;
9
11
mod fmodf;
10
12
mod powf;
11
13
mod round;
@@ -24,8 +26,10 @@ mod hypotf;
24
26
//mod service;
25
27
26
28
pub use self :: {
29
+ ceilf:: ceilf,
27
30
fabs:: fabs,
28
31
fabsf:: fabsf,
32
+ floorf:: floorf,
29
33
fmodf:: fmodf,
30
34
powf:: powf,
31
35
round:: round,
Original file line number Diff line number Diff line change @@ -652,12 +652,12 @@ fn main() -> Result<(), Box<Error>> {
652
652
// With signature `fn(f32) -> f32`
653
653
f32_f32 ! {
654
654
// acosf,
655
- // floorf,
655
+ floorf,
656
656
truncf,
657
657
// asinf,
658
658
// atanf,
659
659
// cbrtf,
660
- // ceilf,
660
+ ceilf,
661
661
// cosf,
662
662
// coshf,
663
663
// exp2f,
You can’t perform that action at this time.
0 commit comments