OCLOperators Number::max ( r : Number ) : Number
This page was created by Peter on 2019-12-06. Last edited by Wikiadmin on 2026-07-29.
You can use max in OCL expressions to choose the greater of two numeric values, whether they are Integer or Real values.
Syntax
self.max(r)| Part | Meaning |
|---|---|
self
|
The first Number value. |
r
|
The Number value to compare with self.
|
| Result | The greatest of self and r, returned as a Number.
|
Use max
Use max when an expression must not return a value below either of two alternatives.
For example, this expression returns 12 because 12 is greater than 8:
12.max(8)This expression returns 3.5 because 3.5 is greater than 2:
2.max(3.5)When both values are equal, the result has that shared value:
7.max(7)The result is 7.
Examples
| Expression | Result | Explanation |
|---|---|---|
5.max(9)
|
9
|
9 is greater than 5. |
14.max(6)
|
14
|
The value of self is already greater.
|
-4.max(-9)
|
-4
|
-4 is greater than -9. |
1.25.max(1.5)
|
1.5
|
The operation compares Real values as Numbers. |
Related operations
Use Number::min when you need the lower of two values instead. For example, 5.min(9) returns 5.
For the broader set of arithmetic and numeric operations available in OCL, see Documentation:OCL Number Operators.
