View source code
							
							
						
								Display the source code in std/checkedint.d from which this
								page was generated on github.
							
						
							Report a bug
							
						
								If you spot a problem with this page, click here to create a
								Bugzilla issue.
							
						
							
								Improve this page
							
							
					
								Quickly fork, edit online, and submit a pull request for this page.
								Requires a signed-in GitHub account. This works well for small changes.
								If you'd like to make larger changes you may want to consider using
								local clone.
							
						Function std.checkedint.Saturate.onOverflow
Implements saturation for operators +, - (unary and binary), *, /,
    %, ^^, &, |, ^, <<, >>, and >>>.
						
				auto onOverflow(string x, Lhs)
				(
				
				  Lhs 
				
				);
				
				
				typeof(Lhs()+Rhs()) onOverflow(string x, Lhs, Rhs)
				(
				
				  Lhs lhs,
				
				  Rhs rhs
				
				);
						
					
				For unary -, onOverflow is called if lhs == Lhs and Lhs is a
    signed type. The function returns Lhs.
For binary operators, the result is as follows:
- Lhsif the result overflows in the positive direction, on division by- .max - 0, or on shifting right by a negative value
- Lhsif the result overflows in the negative direction- .min 
- 0if- lhsis being shifted left by a negative value, or shifted right by a large positive value
Parameters
| Name | Description | 
|---|---|
| x | The operator involved in the opAssignoperation | 
| Lhs | The left-hand side type of the operator ( Lhsis the first argument toChecked) | 
| Rhs | The right-hand side type in the operator | 
Returns
The saturated result of the operator.
Example
writeln(checked!Saturate(intAuthors
License
					Copyright © 1999-2024 by the D Language Foundation | Page generated by ddox.