Function
power(_:_:)
Raises a numeric value to the power of another numeric value.
func power(_ base: any EcoreValue, _ exponent: any EcoreValue) throws -> any EcoreValue
Parameters
base-
The base value
exponent-
The exponent value
Return Value
The result of base raised to the power of exponent
Discussion
Computes the power operation as defined in OCL specification. Supports all numeric types with appropriate type coercion. Result type follows OCL rules: if either operand is Real, result is Real; otherwise Integer.
Type Coercion Rules
-
Integer ^ Integer → Integer (if result fits in ELong range)
-
Real ^ Any → Real
-
Any ^ Real → Real
-
Large integer results promote to EBigInteger
Examples
let result1 = try power(2 as EInt, 3 as EInt) // Result: 8 as EInt
let result2 = try power(2.5 as EDouble, 2 as EInt) // Result: 6.25 as EDouble
let result3 = try power(4 as EInt, 0.5 as EDouble) // Result: 2.0 as EDouble