math.abs
Defined in module
"math"from "math" import abspure fastcall abs(x: number): number
Returns the absolute value of x
Parameters
x | number | the number to take the absolute value of |
Return value
x with its sign removed. The result keeps the type of x: an integer argument gives an integer back, a float argument gives a float back. Use fabs when a float result is wanted regardless of the argument's type.
Notes
The smallest representable integer has no positive counterpart at the same width, so taking its absolute value overflows and returns that same negative value unchanged.
Example
from "math" import abs
println("abs(-3) =", abs(-3))
println("type(abs(-3)) =", type(abs(-3)))
// the result keeps the argument's type: a float argument gives a float back
println("abs(-3.0) =", abs(-3.0))
println("type(abs(-3.0)) =", type(abs(-3.0)))Output:
abs(-3) = 3
type(abs(-3)) = integer
abs(-3.0) = 3
type(abs(-3.0)) = floatSee also
fabs | Returns the absolute value of float(x) |
floor | Rounds x downward to the nearest integer |
ceil | Rounds x upward to the nearest integer |
| math | module index |