Quirrel4.41.0

math.fabs

Defined in module "math"
from "math" import fabs
pure fastcall fabs(x: number): float

Returns the absolute value of float(x)

Parameters

xnumberthe 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

examples/math/fabs.nut
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)) = float

See also

absReturns the absolute value of x
floorRounds x downward to the nearest integer
ceilRounds x upward to the nearest integer
mathmodule index