Absolute value
The absolute value tells you how far a number is from zero.
abs
Simple example
Start−3
Result3
function main()
println(abs(-3))
end
main()
3
Advertisements
Everyday examples
It is −6 degrees outside. How many degrees below zero is that?
Start−6 → 0
Result6
function main()
temperature = -6
println(abs(temperature))
end
main()
6
The target is 15 points and the score is 12. How far apart are they?
Start12 − 15
Result3
function main()
score = 12
target = 15
println(abs((score - target)))
end
main()
3
A lift goes from floor 5 to floor 2. How many floors does it travel?
Start5 → 2
Result3
function main()
start = 5
finish = 2
println(abs((finish - start)))
end
main()
3
Use small signed numbers here. The result is the distance from zero.