widesquare

Wide square operation. This module provides the WideSquare trait which enables squaring operations that return a result type with double the bit width of the input type. This is particularly useful when you need to square a number without worrying about overflow, as the result type can hold the full range of possible values. # Examples

use core::num::traits::WideSquare;

// Squaring a `u8` value to get a `u16` result
let a: u8 = 200;
let result: u16 = a.wide_square();
assert!(result == 40000);

// Squaring a `u128` value to get a `u256` result
let x: u128 = 0xffffffffffffffffffffffffffffffff; // max u128
let wide_result: u256 = x.wide_square(); // No overflow occurs
assert!(wide_result == 0xfffffffffffffffffffffffffffffffe00000000000000000000000000000001);

Available Implementations The trait is implemented for the following type pairs: - i8i16 - i16i32 - i32i64 - i64i128 - u8u16 - u16u32 - u32u64 - u64u128 - u128u256 - u256u512

Fully qualified path: core::num::traits::ops::widesquare

Traits