-
-
Notifications
You must be signed in to change notification settings - Fork 331
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
Make Rust version no_std and improve docs #120
Conversation
Rust/src/lib.rs
Outdated
#[cfg(feature = "no_std")] | ||
// Result is often identical, or otherwise extremely close to, std::f32::sqrt. | ||
// In testing, the worst error seems to be around the order of magnitude of 0.00001% off. | ||
let result = { | ||
if f == 0. { | ||
return 0.; | ||
} | ||
|
||
// Explanation: https://stackoverflow.com/questions/41785416/how-does-this-sqrt-approximation-inline-assembly-function-work | ||
let mut guess = f32::from_bits((f.to_bits() + 0x3f80_0000) >> 1); | ||
|
||
loop { | ||
let new_guess = 0.5 * (guess + f / guess); | ||
if new_guess == guess { | ||
break; | ||
} | ||
guess = new_guess; | ||
} | ||
|
||
guess | ||
}; |
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.
Alternatively, we could port this for the accurate implementation?
Use num-trais for no_std support
Could you pr these changes into the v1.1 branch, I'm getting ready to merge that to master |
I updated the branch and version numbering. However upon changing the base to merge this into, it looks like it created conflicts. I'll have to wait a few hours or possibly until tomorrow until I can resolve those. |
No description provided.