2 + (-3) = -1. But in a saturating math
function with a lower bound of 0, such as saturating_add_pos, the result is 0.
You can use saturating math to make sure your results don’t overflow the allowed range of integers, or to force a result
to be greater than or equal to zero.
All saturating math functions are in the Alternatively, add the schema to your search path:
toolkit_experimental schema. You must use schema-qualified names:Available functions
Addition
saturating_add(): add two numbers, saturating at the 32-bit integer bounds instead of overflowingsaturating_add_pos(): add two numbers, saturating at 0 for the minimum bound
Subtraction
saturating_sub(): subtract one number from another, saturating at the 32-bit integer bounds instead of overflowingsaturating_sub_pos(): subtract one number from another, saturating at 0 for the minimum bound
Multiplication
saturating_mul(): multiply two numbers, saturating at the 32-bit integer bounds instead of overflowing