Module int_sqrt

Source
Expand description

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.

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.
signed_fn ๐Ÿ”’
Generates an i* function that returns the integer square root of any nonnegative input of a specific signed integer type.
unsigned_fn ๐Ÿ”’
Generates a u* function that returns the integer square root of any input of a specific unsigned integer type.

Constantsยง

U8_ISQRT_WITH_REMAINDER ๐Ÿ”’
This array stores the integer square roots and remainders of each u8 value. 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.

Functionsยง

i8 ๐Ÿ”’ โš 
Returns the integer square root of any nonnegative i8 input.
i16 ๐Ÿ”’ โš 
Returns the integer square root of any nonnegative i16 input.
i32 ๐Ÿ”’ โš 
Returns the integer square root of any nonnegative i32 input.
i64 ๐Ÿ”’ โš 
Returns the integer square root of any nonnegative i64 input.
i128 ๐Ÿ”’ โš 
Returns the integer square root of any nonnegative i128 input.
panic_for_negative_argument ๐Ÿ”’
Instantiate this panic logic once, rather than for all the isqrt methods on every single primitive type.
u8 ๐Ÿ”’
Returns the integer square root of any u8 input.
u16 ๐Ÿ”’
Returns the integer square root of any u16 input.
u32 ๐Ÿ”’
Returns the integer square root of any u32 input.
u64 ๐Ÿ”’
Returns the integer square root of any u64 input.
u16_stages ๐Ÿ”’
Takes the normalized u16 input and gets its normalized integer square root.
u32_stages ๐Ÿ”’
Takes the normalized u32 input and gets its normalized integer square root.
u64_stages ๐Ÿ”’
Takes the normalized u64 input and gets its normalized integer square root.
u128 ๐Ÿ”’
Returns the integer square root of any u128 input.
u128_stages ๐Ÿ”’
Takes the normalized u128 input and gets its normalized integer square root.