File tree Expand file tree Collapse file tree 1 file changed +23
-3
lines changed
Expand file tree Collapse file tree 1 file changed +23
-3
lines changed Original file line number Diff line number Diff line change 33use crate :: { Error , Result , m} ;
44
55super :: libm_simple!( @1 ceil, floor, trunc) ;
6- super :: libm_simple!( @2 nextafter) ;
6+
7+ /// Return the next floating-point value after x towards y.
8+ ///
9+ /// If steps is provided, move that many steps towards y.
10+ /// Steps must be non-negative.
11+ #[ inline]
12+ pub fn nextafter ( x : f64 , y : f64 , steps : Option < u64 > ) -> f64 {
13+ match steps {
14+ Some ( n) => {
15+ let mut result = x;
16+ for _ in 0 ..n {
17+ result = crate :: m:: nextafter ( result, y) ;
18+ if result == y {
19+ break ;
20+ }
21+ }
22+ result
23+ }
24+ None => crate :: m:: nextafter ( x, y) ,
25+ }
26+ }
727
828/// Return the absolute value of x.
929#[ inline]
@@ -146,10 +166,10 @@ pub fn ulp(x: f64) -> f64 {
146166 if x. is_infinite ( ) {
147167 return x;
148168 }
149- let x2 = super :: nextafter ( x, f64:: INFINITY ) ;
169+ let x2 = nextafter ( x, f64:: INFINITY , None ) ;
150170 if x2. is_infinite ( ) {
151171 // Special case: x is the largest positive representable float
152- let x2 = super :: nextafter ( x, f64:: NEG_INFINITY ) ;
172+ let x2 = nextafter ( x, f64:: NEG_INFINITY , None ) ;
153173 return x - x2;
154174 }
155175 x2 - x
You can’t perform that action at this time.
0 commit comments