Using Integer and Float
The complete source of builtInTypes_integer.ek9, compiled by the EK9 compiler. Shown on builtInTypes.html.
#!ek9 defines module site.builtintypes.integer defines function integerExamples() -> zero as Integer alsoZero as Integer ninety as Integer stdout <- Stdout() //Some examples of using Integer i1 <- -9223372036854775808 hashCode <- #? i1 //results in -2147483648 asFloat <- #^ i1 //promotion to Float results in -9.223372036854776E18 //Division operations with zero nonResult <- zero / ninety //result is 0 (zero) nonResult := ninety / zero //result is un set i.e not known nonResult := zero / alsoZero //result is un set stdout.println(`${hashCode} ${asFloat} ${nonResult?}`) integerPipeline() stdout <- Stdout() theValues as List of Integer := List() //create a list to capture values in //Simple pipeline processing intSum <- for i in 1 ... 11 by 2 | tee in theValues | collect as Integer //theValues has the following contents [1, 3, 5, 7, 9, 11] //intSum has the value 36 stdout.println(`${theValues} ${intSum}`) floatExamples() -> zero as Float alsoZero as Float ninety as Float stdout <- Stdout() //Some examples of using Float i1 <- -4.9E-324 hashCode <- #? i1 //results in -2147483647 //Division operations with zero nonResult <- zero / ninety //result is 0.0 (zero) nonResult := ninety / zero //result is un set i.e not known nonResult := zero / alsoZero //result is un set stdout.println(`${hashCode} ${nonResult?}`) defines program IntegerUse() integerExamples(0, 0, 90) integerPipeline() floatExamples(0.0, 0.0, 90.0)
Download builtInTypes_integer.ek9
Output
-2147483648 -9.223372036854776E18 false [1, 3, 5, 7, 9, 11] 36 -2147483647 false