Conversions

HCL Detect Expression Language supports explicit conversions via casts using a function call syntax. The name of the function is the name of the type we want to cast to.

Examples:

  • Casting an Int32 to a String: String(14) yields "14"
  • Casting a String to a Double: Double("4.5") yields 4.5
  • Casting a String to a Double: Double("nan") yields NaN (not a number)

HCL Detect Expression Language supports implicit conversions (aka coercions) as well. When two integers of different types are involved in an operation, the one that has the smaller number of bits is coerced into the wider type. When an integer is involved in an operation with a Double it is coerced into a Double. Also note that, in such operations, Int64 values that cannot be represented exactly will be rounded to the closest Double value.

Examples:

  • Coercion with integers of different bit-lengths: count/2 has type Int64, assuming count is of type Int64 (this has the same semantics as the expression count / Int64(2))
  • Coercion involving an Int32 and a Double: timestamp / 1000 has type Double, assuming timestamp is of type Double (this has the same semantics as the expression timestamp / Double(1000))