diff options
| author | bors <bors@rust-lang.org> | 2023-09-29 07:35:44 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-09-29 07:35:44 +0000 |
| commit | b8536c1aa1973dd2438841815b1eeec129480e45 (patch) | |
| tree | c8ef27dc78f977d2db8d7bb22f4ac8714fb653a2 /compiler/rustc_parse/src/parser/expr.rs | |
| parent | c1f86f0bc87eaa0cf16bcf3de38793096ec4db94 (diff) | |
| parent | 25648de28f10799fa6274f64fa12475292231c72 (diff) | |
| download | rust-b8536c1aa1973dd2438841815b1eeec129480e45.tar.gz rust-b8536c1aa1973dd2438841815b1eeec129480e45.zip | |
Auto merge of #116176 - FedericoStra:isqrt, r=dtolnay
Add "integer square root" method to integer primitive types For every suffix `N` among `8`, `16`, `32`, `64`, `128` and `size`, this PR adds the methods ```rust const fn uN::isqrt() -> uN; const fn iN::isqrt() -> iN; const fn iN::checked_isqrt() -> Option<iN>; ``` to compute the [integer square root](https://en.wikipedia.org/wiki/Integer_square_root), addressing issue #89273. The implementation is based on the [base 2 digit-by-digit algorithm](https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Binary_numeral_system_(base_2)) on Wikipedia, which after some benchmarking has proved to be faster than both binary search and Heron's/Newton's method. I haven't had the time to understand and port [this code](http://atoms.alife.co.uk/sqrt/SquareRoot.java) based on lookup tables instead, but I'm not sure whether it's worth complicating such a function this much for relatively little benefit.
Diffstat (limited to 'compiler/rustc_parse/src/parser/expr.rs')
0 files changed, 0 insertions, 0 deletions
