Logo

Programming-Idioms

Assign to y the absolute value of the number n
New implementation

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
import "math"
y := math.Abs(x)
import "math/big"
y := new(big.Float)
y.Abs(x)
import "math/big"
y := new(big.Int)
y.Abs(x)
y := x
if y < 0 {
	y = -x
}
y = abs(n)
from math import fabs
y = fabs(n)
y = n.abs