File tree Expand file tree Collapse file tree 4 files changed +42
-3
lines changed Expand file tree Collapse file tree 4 files changed +42
-3
lines changed Original file line number Diff line number Diff line change @@ -347,7 +347,6 @@ impl F32Ext for f32 {
347
347
pub trait F64Ext : private:: Sealed {
348
348
fn floor ( self ) -> Self ;
349
349
350
- #[ cfg( todo) ]
351
350
fn ceil ( self ) -> Self ;
352
351
353
352
fn round ( self ) -> Self ;
@@ -455,7 +454,6 @@ impl F64Ext for f64 {
455
454
floor ( self )
456
455
}
457
456
458
- #[ cfg( todo) ]
459
457
#[ inline]
460
458
fn ceil ( self ) -> Self {
461
459
ceil ( self )
Original file line number Diff line number Diff line change
1
+ use core:: f64;
2
+
3
+ const TOINT : f64 = 1. / f64:: EPSILON ;
4
+
5
+ #[ inline]
6
+ pub fn ceil ( x : f64 ) -> f64 {
7
+ let u: u64 = x. to_bits ( ) ;
8
+ let e: i64 = ( u >> 52 & 0x7ff ) as i64 ;
9
+ let y: f64 ;
10
+
11
+ if e >= 0x3ff + 52 || x == 0. {
12
+ return x;
13
+ }
14
+ // y = int(x) - x, where int(x) is an integer neighbor of x
15
+ y = if ( u >> 63 ) != 0 {
16
+ x - TOINT + TOINT - x
17
+ } else {
18
+ x + TOINT - TOINT - x
19
+ } ;
20
+ // special case because of non-nearest rounding modes
21
+ if e <= 0x3ff - 1 {
22
+ force_eval ! ( y) ;
23
+ return if ( u >> 63 ) != 0 { -0. } else { 1. } ;
24
+ }
25
+ if y < 0. {
26
+ x + y + 1.
27
+ } else {
28
+ x + y
29
+ }
30
+ }
31
+
32
+ #[ cfg( test) ]
33
+ mod tests {
34
+ #[ test]
35
+ fn sanity_check ( ) {
36
+ assert_eq ! ( super :: ceil( 1.1 ) , 2.0 ) ;
37
+ assert_eq ! ( super :: ceil( 2.9 ) , 3.0 ) ;
38
+ }
39
+ }
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ macro_rules! force_eval {
6
6
} ;
7
7
}
8
8
9
+ mod ceil;
9
10
mod ceilf;
10
11
mod cosf;
11
12
mod expf;
@@ -35,6 +36,7 @@ mod trunc;
35
36
mod truncf;
36
37
37
38
// Use separated imports instead of {}-grouped imports for easier merging.
39
+ pub use self :: ceil:: ceil;
38
40
pub use self :: ceilf:: ceilf;
39
41
pub use self :: cosf:: cosf;
40
42
pub use self :: expf:: expf;
Original file line number Diff line number Diff line change @@ -700,7 +700,7 @@ f64_f64! {
700
700
// asin,
701
701
// atan,
702
702
// cbrt,
703
- // ceil,
703
+ ceil,
704
704
// cos,
705
705
// cosh,
706
706
// exp,
You can’t perform that action at this time.
0 commit comments