Finding the square root in embedded with #![no_std]

I am making a project in which I am using the stm32f3discovery board and need to know the square root of a a decimal number, there is obviously the function in the std library but as I cannot use the std library, is there a way in which I can find the square root without it?


When you say "decimal", do you mean f32 or f64? The libm crate has pure-rust implementations of most of these functions.


What do you mean by “decimal number” and which square root “function” in std are you referring to?

In case you mean floating point numbers, .sqrt() is a method on f64 and f32, so it ought to work with or without std (as far as I can tell).

It does not work without std, and I wish the documentation reflected this.

Okay, nevermind, I never used #![no_std] myself before. The documentation is indeed pretty confusing about this. What is the fundamental reason why those methods are not provided with #![no_std]?

For some targets, there are native instructions for these methods which LLVM will try to use, but in general it may have to fall back to the system libm -- which may not exist in no_std environments.

The micromath crate also provides sqrt that is optimized for embedded systems (but less accurate than libm's)

Yeah this crate is perfect, thank you