I'm working in python3.6 on linux and came across a pretty obvious failure of the abs() function. My variable x
ended up as a very large negative number (possibly -inf
), but the absolute value abs()
function still returned a negative number, which shouldn't be possible. I put in a quick fix for my code by just adding 0.1 to the input of abs()
but.... am I misunderstanding how abs()
should be used?
$> x
-9223372036854775808
$> abs(x)
-9223372036854775808
$> np.abs(x)
-9223372036854775808
$> abs(x+.1)
9.223372036854776e+18
$> np.abs(x+.1)
9.223372036854776e+18
EDIT: Solved below, but it boils down to x
being a numpy.int64
and not just int
, unbeknownst to me.
x= -9223372036854775808
thenabs(x)
and it produced a positive resultprint(x, type(x))
shows what?