Modification operators on a Float

The complete source of operators_mutation.ek9, compiled by the EK9 compiler. Shown on operators.html.

#!ek9
defines module site.operators.mutation

  defines program

    Mutation()
      stdout <- Stdout()

      aFloat <- 22.9 //Create a new floating point value
      aFloat += 17.1 //Add the value into the variable aFloat
      //aFloat would now have the value of 40.0

      aFloat -= 7.5 //Subtract the value from the variable aFloat
      //aFloat would now have the value of 32.5

      aFloat *= 3 //Multiply aFloat by the value
      //aFloat would now have the value of 97.5

      aFloat /= 2.5 //Divide aFloat by the value
      //aFloat would now have the value of 39.0

      aFloat++ //Increment aFloat by 1.0
      //aFloat would now have the value of 40.0

      aFloat-- //Decrement aFloat by 1.0
      //aFloat would now have the value of 39.0 again

      bFloat <- Float() //Create a new floating point value but not yet set
      bFloat := aFloat //Assign the variable and update
      aFloat++ //Increment aFloat by 1.0, but note bFloat will also change

      cFloat <- Float() //Create another new floating point value but not yet set
      cFloat :=: aFloat //Copy the contents of the variable and update
      aFloat++ //Increment aFloat by 1.0, but note cFloat will not change

      stdout.println(`aFloat ${aFloat}, bFloat ${bFloat}, cFloat ${cFloat}`)

Download operators_mutation.ek9

Output

aFloat 41.0, bFloat 41.0, cFloat 40.0