colon operator

Syntax

  • float[] base : limit
  • float[] base : increment : limit
Note:

The colon operator is only available as a parameter for the array initialization function and the index operator (inside a bracket [] notation).

Parameters

  1. basefloat
    Starting value of sequence.
  2. incrementfloat
    Successively added value to base. Must be positive for an ascending sequence base<=limit or negative for a descending sequence base>=limit. Default is 1.
  3. limitfloat
    Maximum/minimum value which is not exceeded.

Returns

An array containing a sequence of float values

[ base, base + increment, base + 2*increment, ... ]

where the last element does not exceed limit.

Parameters base, increment and limit are given in a colon-separated notation.

Note:

The size of the returned array is limited. It can be configured in the Procedural Runtime preferences (Default: 100000).

Related

Example

Binary colon operator

const a = [2   : 4]      // (3)[2,3,4]
const b = [0.5 : 3]      // (3)[0.5,1.5,2.5]
const c = [4   : 2]      // (0)[]

Ternary colon operator

const a = [1 :  0.5 : 3] // (5)[1,1.5,2,2.5,3]
const b = [4 :   -1 : 2] // (3)[4,3,2]
const c = [1 : -0.5 : 2] // (0)[]
const d = [1 : -0.5 : 1] // (1)[1]
const e = [1 :    0 : 1] // (0)[]

Floating point imprecision

The computation of sequence values base+i*increment suffers from floating point imprecision. Their exact values might be unexpected. This is not always noticeable when printing values due to an implicit rounding.

const a = [0 : 0.15 : 0.5]

Init --> print(a)                        // (4)[0,0.15,0.3,0.45]
         print(a[3] == 0.45)             // false
         print(abs(a[3] - 0.45) < 1e-10) // true