Commit Graph

9 Commits

Author SHA1 Message Date
Michael Pfaff 83649f11fa
Make const 2022-03-01 18:30:30 -05:00
Joe Richey e620eeed5e Remove impl_isqrt macro
The implementation can now just use a normal generic impl. Note that
this is tecnically a minor breaking change, as if a user has both:
  - A custom num_traits::PrimInt impl
  - A custom IntegerSquareRoot impl

Their code will no longer compile

Signed-off-by: Joe Richey <joerichey@google.com>
2020-09-08 13:56:05 +01:00
Joe Richey 1e02bdb415 Use leading_zeros to compute initial bit
This increases performance on processors with lzcnt instructions.

Signed-off-by: Joe Richey <joerichey@google.com>
2020-09-08 04:51:18 -07:00
Joe Richey 0445b3e5c1
Use improved algorithm that only uses shifts
This new algorithm (taken from Wikipedia) only uses shifts, addditions,
and subtrations. On my x86_64 machine, the benchmarks are over twice as
fast.

This also takes num-traits as a dependancy, so that the implementation
can be a normal generic function, instread of a macro.

Signed-off-by: Joe Richey <joerichey@google.com>
2020-09-08 04:50:50 -07:00
Joe Richey 260148e029
Simplify impl_isqrt macro
We don't need multiple cases in the macro_rules!

Signed-off-by: Joe Richey <joerichey@google.com>
2020-09-07 20:19:44 -07:00
Richard Dodd 9e6ffa6f81 Fix overflow in some edge cases. 2020-01-24 12:25:14 +00:00
Sergey Pepyakin 01bb91452f Add u128 and i128. 2018-10-30 12:22:24 +01:00
Richard Dodd 5bbfb9187d Add no_std and fix tests 2018-03-02 21:37:51 +00:00
Richard Dodd 00aabcfe32 First commit 2017-10-23 13:29:42 +01:00