Documentation Language: Swift

Function

round(_:)

Returns the rounded value to the nearest integer (OCL Real.round()).

func round(_ value: any EcoreValue) throws -> EInt

Parameters

value

The Real value to round

Return Value

The rounded value as an Integer

Discussion

Computes rounding as defined in OCL specification: “The integer that is closest to self. When there are two such integers, the largest one.” Only accepts Real (Double) values as per OCL standard.

Examples

let result1 = try round(3.6 as EDouble)  // Result: 4
let result2 = try round(3.5 as EDouble)  // Result: 4 (ties go to larger)
let result3 = try round(-2.3 as EDouble) // Result: -2