Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!

Idiom #355 Absolute value

Assign to y the absolute value of the number n

import "math/big"
y := new(big.Float)
y.Abs(x)
import "math"
y := math.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

New implementation...
< >
programming-idioms.org