-
Notifications
You must be signed in to change notification settings - Fork 0
Fix wasm build #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix wasm build #13
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,211 @@ | ||
| //! Pure Rust implementations of libm functions using the libm crate. | ||
| //! Used on targets without native libm (e.g., WASM). | ||
|
|
||
| // Trigonometric functions | ||
|
|
||
| #[inline(always)] | ||
| pub fn acos(n: f64) -> f64 { | ||
| libm::acos(n) | ||
| } | ||
|
|
||
| #[inline(always)] | ||
| pub fn asin(n: f64) -> f64 { | ||
| libm::asin(n) | ||
| } | ||
|
|
||
| #[inline(always)] | ||
| pub fn atan(n: f64) -> f64 { | ||
| libm::atan(n) | ||
| } | ||
|
|
||
| #[inline(always)] | ||
| pub fn atan2(y: f64, x: f64) -> f64 { | ||
| libm::atan2(y, x) | ||
| } | ||
|
|
||
| #[inline(always)] | ||
| pub fn cos(n: f64) -> f64 { | ||
| libm::cos(n) | ||
| } | ||
|
|
||
| #[inline(always)] | ||
| pub fn sin(n: f64) -> f64 { | ||
| libm::sin(n) | ||
| } | ||
|
|
||
| #[inline(always)] | ||
| pub fn tan(n: f64) -> f64 { | ||
| libm::tan(n) | ||
| } | ||
|
|
||
| // Hyperbolic functions | ||
|
|
||
| #[inline(always)] | ||
| pub fn acosh(n: f64) -> f64 { | ||
| libm::acosh(n) | ||
| } | ||
|
|
||
| #[inline(always)] | ||
| pub fn asinh(n: f64) -> f64 { | ||
| libm::asinh(n) | ||
| } | ||
|
|
||
| #[inline(always)] | ||
| pub fn atanh(n: f64) -> f64 { | ||
| libm::atanh(n) | ||
| } | ||
|
|
||
| #[inline(always)] | ||
| pub fn cosh(n: f64) -> f64 { | ||
| libm::cosh(n) | ||
| } | ||
|
|
||
| #[inline(always)] | ||
| pub fn sinh(n: f64) -> f64 { | ||
| libm::sinh(n) | ||
| } | ||
|
|
||
| #[inline(always)] | ||
| pub fn tanh(n: f64) -> f64 { | ||
| libm::tanh(n) | ||
| } | ||
|
|
||
| // Exponential and logarithmic functions | ||
|
|
||
| #[inline(always)] | ||
| pub fn exp(n: f64) -> f64 { | ||
| libm::exp(n) | ||
| } | ||
|
|
||
| #[inline(always)] | ||
| pub fn exp2(n: f64) -> f64 { | ||
| libm::exp2(n) | ||
| } | ||
|
|
||
| #[inline(always)] | ||
| pub fn expm1(n: f64) -> f64 { | ||
| libm::expm1(n) | ||
| } | ||
|
|
||
| #[inline(always)] | ||
| pub fn log(n: f64) -> f64 { | ||
| libm::log(n) | ||
| } | ||
|
|
||
| #[inline(always)] | ||
| pub fn log10(n: f64) -> f64 { | ||
| libm::log10(n) | ||
| } | ||
|
|
||
| #[inline(always)] | ||
| pub fn log1p(n: f64) -> f64 { | ||
| libm::log1p(n) | ||
| } | ||
|
|
||
| #[inline(always)] | ||
| pub fn log2(n: f64) -> f64 { | ||
| libm::log2(n) | ||
| } | ||
|
|
||
| // Power functions | ||
|
|
||
| #[inline(always)] | ||
| pub fn cbrt(n: f64) -> f64 { | ||
| libm::cbrt(n) | ||
| } | ||
|
|
||
| #[inline(always)] | ||
| pub fn hypot(x: f64, y: f64) -> f64 { | ||
| libm::hypot(x, y) | ||
| } | ||
|
|
||
| #[inline(always)] | ||
| pub fn pow(x: f64, y: f64) -> f64 { | ||
| libm::pow(x, y) | ||
| } | ||
|
|
||
| #[inline(always)] | ||
| pub fn sqrt(n: f64) -> f64 { | ||
| libm::sqrt(n) | ||
| } | ||
|
|
||
| // Floating-point manipulation functions | ||
|
|
||
| #[inline(always)] | ||
| pub fn ceil(n: f64) -> f64 { | ||
| libm::ceil(n) | ||
| } | ||
|
|
||
| #[inline(always)] | ||
| pub fn copysign(x: f64, y: f64) -> f64 { | ||
| libm::copysign(x, y) | ||
| } | ||
|
|
||
| #[inline(always)] | ||
| pub fn fabs(n: f64) -> f64 { | ||
| libm::fabs(n) | ||
| } | ||
|
|
||
| #[inline(always)] | ||
| pub fn floor(n: f64) -> f64 { | ||
| libm::floor(n) | ||
| } | ||
|
|
||
| #[inline(always)] | ||
| pub fn fmod(x: f64, y: f64) -> f64 { | ||
| libm::fmod(x, y) | ||
| } | ||
|
|
||
| #[inline(always)] | ||
| pub fn frexp(n: f64, exp: &mut i32) -> f64 { | ||
| let (mantissa, exponent) = libm::frexp(n); | ||
| *exp = exponent; | ||
| mantissa | ||
| } | ||
|
|
||
| #[inline(always)] | ||
| pub fn ldexp(x: f64, n: i32) -> f64 { | ||
| libm::ldexp(x, n) | ||
| } | ||
|
|
||
| #[inline(always)] | ||
| pub fn modf(n: f64, iptr: &mut f64) -> f64 { | ||
| let (frac, int) = libm::modf(n); | ||
| *iptr = int; | ||
| frac | ||
| } | ||
|
|
||
| #[inline(always)] | ||
| pub fn nextafter(x: f64, y: f64) -> f64 { | ||
| libm::nextafter(x, y) | ||
| } | ||
|
|
||
| #[inline(always)] | ||
| pub fn remainder(x: f64, y: f64) -> f64 { | ||
| libm::remainder(x, y) | ||
| } | ||
|
|
||
| #[inline(always)] | ||
| pub fn trunc(n: f64) -> f64 { | ||
| libm::trunc(n) | ||
| } | ||
|
|
||
| // Special functions | ||
|
|
||
| #[inline(always)] | ||
| pub fn erf(n: f64) -> f64 { | ||
| libm::erf(n) | ||
| } | ||
|
|
||
| #[inline(always)] | ||
| pub fn erfc(n: f64) -> f64 { | ||
| libm::erfc(n) | ||
| } | ||
|
|
||
| // Platform-specific sincos (fallback: call sin and cos separately) | ||
|
|
||
| #[cfg(feature = "complex")] | ||
| #[inline(always)] | ||
| pub fn sincos(x: f64) -> (f64, f64) { | ||
| (libm::sin(x), libm::cos(x)) | ||
| } | ||
|
Comment on lines
+207
to
+211
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # Check for sincos declaration in m_sys.rs
grep -n "sincos" src/m_sys.rsRepository: RustPython/pymath Length of output: 178 🏁 Script executed: # Check for m::sincos usage in cmath module
rg -n 'm::sincos' src/cmath/Repository: RustPython/pymath Length of output: 349 🏁 Script executed: # Check the module structure to understand how m:: is resolved
cat -n src/lib.rs | head -80Repository: RustPython/pymath Length of output: 3360 🏁 Script executed: # Look for any sincos declarations across the codebase
rg -n "fn sincos" src/ --type rsRepository: RustPython/pymath Length of output: 87 🏁 Script executed: # Check if there's feature gating around sincos in m_rust.rs
rg -B 5 -A 5 "sincos" src/m_rust.rsRepository: RustPython/pymath Length of output: 316 🏁 Script executed: # Get line count of m_sys.rs
wc -l src/m_sys.rsRepository: RustPython/pymath Length of output: 76 🏁 Script executed: # Read m_sys.rs to see if sincos is missing or if there's feature gating
cat -n src/m_sys.rsRepository: RustPython/pymath Length of output: 2731 🏁 Script executed: # Verify compilation by checking Cargo.toml features
cat src/../Cargo.toml | grep -A 20 "\[features\]"Repository: RustPython/pymath Length of output: 992 Add The 🤖 Prompt for AI Agents |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Signature mismatch:
frexpandmodfuse references vs raw pointers.The
m_sys.rsFFI declarations use raw pointers (*mut i32,*mut f64), while these pure Rust wrappers use safe references (&mut i32,&mut f64). If callers use raw pointers (common in FFI-adjacent code), this will cause compilation errors on WASM.Verify if existing call sites use references or raw pointers:
🤖 Prompt for AI Agents