Need Integer:sqrt in std lib

Rust doesn't have an Integer Squareroot function, but needs it.

I raised this issue in Ruby, and they included it in version 2.5 (2.7 was just released Dec 25, 2019).

For large integers, doing something like: (n as f64).sqrt() as usize
will start producing errors above a certain size. This is an inherent limitation of floating point math.

See article here describing problem:

This floating point conversion bug starts to show up early for large 64-bit integers.
This is a necessary fix to implement many numerical algorithms correctly, e.g. in cryptography, which use very large integers.

Discussion in Ruby issue tracker on which implementation to use.

I note that integer-sqrt crate implements basically the same algorithm used in Ruby.


See this answer in a parallel thread to one of your similar requests.

1 Like

Thanks for the heads up.

Part of this process is learning what is part of the std lib and what|where to find external functionality, especially coming from languages (Ruby, Nim) which have these available by default.

I'll check out the crate.

I guess there's a directory of all the crates somewhere, right?

1 Like or The Rust standard library is small by design.

Thanks. I'll start looking there for stuff from now on.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.