@Abs (JavaScript™)
Returns the absolute (unsigned) value of a number.
Defined in
@Functions (JavaScript)Syntax
@Abs(value:double) : double
Parameter | Description |
---|---|
value |
A number or an array of numbers. |
Return value | Description |
---|---|
double |
The absolute value of the number or each number in the array. |
Examples
This example returns the square root of an absolute value.function p(stuff) {
print("<<<" + stuff + ">>>");
}
function sq(n) {
return(Math.sqrt(@Abs(n)));
}
p("sq of 9 = " + sq(9));
p("sq of -9 = " + sq(-9));
This example returns the positive difference between two numbers.
function p(stuff) {
print("<<<" + stuff + ">>>");
}
function diff(n1, n2) {
return(@Abs(n1 - n2));
}
p("diff(15, 5) = " + diff(15, 5));
p("diff(5, 15) = " + diff(5, 15));
p("diff(-15, 5) = " + diff(-15, -5));
// all result in 10