pub trait SaturatingFrom<T>: Sized {
    fn saturating_from(value: T) -> Self;
}
Expand description

Converts a value from one type to another, where if the conversion is not exact the result is set to the maximum or minimum value of the result type, whichever is closer.

Required Methods

Implementations on Foreign Types

Converts a value to its own type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to its own type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to its own type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to its own type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to its own type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to its own type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to its own type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to its own type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to its own type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to its own type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to its own type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to its own type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. This conversion is always valid and always leaves the value unchanged.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.

Let $W$ be the width of the target type.

If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$

If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$

Worst-case complexity

Constant time and additional memory.

Examples

See here.

Implementors