Sign functions ( abs, neg, sign )
Help Contents
Logo and Mathematics
Mathematical functions (guide)
Sign functions ( abs, neg, sign )
Sign functions ( abs, neg, sign )
The sign functions in Logo are used when you need to examing or change the sign of a number.
If you say the function abs, then Logo will remove the sign of a value and convert it ito a positive number.
The other function is neg and it negates a number - if it is positive, after applying the action the result will be negative, and vice versa.
Actually, negating a value is the same as subtracting it from 0.
print abs 20 ; 20
print abs -15 ; 15
print neg 10 ; -10
print neg -7 ; 7
Both abs and neg return the same numbers, but eventually with changed signs.
In order to see what the sign of a value is, you may ask the function sign.
It will return -1 if a value is negative, +1 if it is positive, and 0 if it is zero.
print sign -3 ; -1
print sign 0 ; 0
print sign 4 ; 1