math.fabs
Defined in module
"math"from "math" import fabsReturns the absolute value of float(x)
Parameters
x | number | the number to take the absolute value of |
Return value
The absolute value of x, always as a float, even when x is an integer.
Notes
Unlike abs, the result type never depends on the argument's type. Use abs when the result should keep the argument's own type.
Example
from "math" import fabs
println("fabs(-3.5) =", fabs(-3.5))
println("fabs(3.5) =", fabs(3.5))
// unlike abs, fabs always returns a float, even for an integer argument
println("fabs(-3) =", fabs(-3))
println("type(fabs(-3)) =", type(fabs(-3)))Output:
fabs(-3.5) = 3.5
fabs(3.5) = 3.5
fabs(-3) = 3
type(fabs(-3)) = floatSee also
abs | Returns the absolute value of x |
floor | Rounds x downward to the nearest integer |
ceil | Rounds x upward to the nearest integer |
| math | module index |