Skip to content

MAP Expression

MAP linearly maps a numeric value from one range to another and then clamps the result to the output range.

Syntax

MAP{value,fromLow,fromHigh,toLow,toHigh}

All five arguments are parsed as numbers. fromLow and fromHigh must be different; the production implementation rejects a zero-width input range.

The calculation is:

(value - fromLow) * (toHigh - toLow) / (fromHigh - fromLow) + toLow

The calculated value is then clamped between min(toLow,toHigh) and max(toLow,toHigh), so an inverted output range (toLow > toHigh) is supported.

Examples

These forms are already covered by ACE's expression tests:

MAP{50,0,100,0,200}          -> 100
MAP{200,0,100,0,200}         -> 200
MAP{0,0,255,255,0}           -> 255
MAP{255,0,255,255,0}         -> 0
MAP{512,0,1023,0,255}        -> approximately 127.62

The second example demonstrates automatic clamping above the input range. The next two demonstrate an inverted output range.