Module int_sqrt
These functions use the Karatsuba square root algorithm to compute the integer square root for the primitive integer types.
The signed integer functions can only handle nonnegative inputs, so that must be checked before calling those.
Functions
- panic_for_negative_argument Instantiate this panic logic once, rather than for all the isqrt methods on every single primitive type.
-
u128
Returns the integer square root of any
u128input. -
u128_stages
Takes the normalized
u128input and gets its normalized integer square root. -
u16
Returns the integer square root of any
u16input. -
u16_stages
Takes the normalized
u16input and gets its normalized integer square root. -
u32
Returns the integer square root of any
u32input. -
u32_stages
Takes the normalized
u32input and gets its normalized integer square root. -
u64
Returns the integer square root of any
u64input. -
u64_stages
Takes the normalized
u64input and gets its normalized integer square root. -
u8
Returns the integer square root of any
u8input.
Constants
-
U8_ISQRT_WITH_REMAINDER
This array stores the integer square roots and remainders of each
u8value. For example,U8_ISQRT_WITH_REMAINDER[17]will be(4, 1)because the integer square root of 17 is 4 and because 17 is 1 higher than 4 squared.
Macros
- first_stage Generates the first stage of the computation after normalization.
- last_stage Generates the last stage of the computation before denormalization.
- middle_stage Generates a middle stage of the computation.
-
unsigned_fn
Generates a
u*function that returns the integer square root of any input of a specific unsigned integer type.