@@ -17,6 +17,9 @@ use crate::obj::objtype;
17
17
use crate :: pyobject:: { PyObjectRef , PyResult , TypeProtocol } ;
18
18
use crate :: vm:: VirtualMachine ;
19
19
20
+ #[ cfg( not( target_arch = "wasm32" ) ) ]
21
+ use libc:: c_double;
22
+
20
23
use std:: cmp:: Ordering ;
21
24
22
25
// Helper macro:
@@ -291,6 +294,21 @@ fn math_modf(x: IntoPyFloat, _vm: &VirtualMachine) -> (f64, f64) {
291
294
( x. fract ( ) , x. trunc ( ) )
292
295
}
293
296
297
+ #[ cfg( not( target_arch = "wasm32" ) ) ]
298
+ fn math_nextafter ( x : IntoPyFloat , y : IntoPyFloat ) -> PyResult < f64 > {
299
+ extern "C" {
300
+ fn nextafter ( x : c_double , y : c_double ) -> c_double ;
301
+ }
302
+ let x = x. to_f64 ( ) ;
303
+ let y = y. to_f64 ( ) ;
304
+ Ok ( unsafe { nextafter ( x, y) } )
305
+ }
306
+
307
+ #[ cfg( target_arch = "wasm32" ) ]
308
+ fn math_nextafter ( x : IntoPyFloat , y : IntoPyFloat , vm : & VirtualMachine ) -> PyResult < f64 > {
309
+ Err ( vm. new_not_implemented_error ( "not implemented for this platform" . to_string ( ) ) )
310
+ }
311
+
294
312
fn fmod ( x : f64 , y : f64 ) -> f64 {
295
313
if y. is_infinite ( ) && x. is_finite ( ) {
296
314
return x;
@@ -415,6 +433,8 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
415
433
// Factorial function
416
434
"factorial" => ctx. new_function( math_factorial) ,
417
435
436
+ "nextafter" => ctx. new_rustfunc( math_nextafter) ,
437
+
418
438
// Constants:
419
439
"pi" => ctx. new_float( std:: f64 :: consts:: PI ) , // 3.14159...
420
440
"e" => ctx. new_float( std:: f64 :: consts:: E ) , // 2.71..
0 commit comments