From 8425d558165e7eacf797d910f3509bc231abb084 Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Mon, 10 Nov 2014 12:32:11 -0500 Subject: [PATCH] fix #8968: abs(big(-0.0)) backport of a42a54bf5ba439850d4d78dc013c397e49cac79b --- base/number.jl | 2 +- test/numbers.jl | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/base/number.jl b/base/number.jl index ac4cee8c7f00b..85fd2506b30bc 100644 --- a/base/number.jl +++ b/base/number.jl @@ -21,7 +21,7 @@ last(x::Number) = x divrem(x,y) = (div(x,y),rem(x,y)) signbit(x::Real) = x < 0 sign(x::Real) = ifelse(x < 0, oftype(x,-1), ifelse(x > 0, one(x), x)) -abs(x::Real) = ifelse(x < 0, -x, x) +abs(x::Real) = ifelse(signbit(x), -x, x) abs2(x::Real) = x*x copysign(x::Real, y::Real) = ifelse(signbit(x)!=signbit(y), -x, x) diff --git a/test/numbers.jl b/test/numbers.jl index 6a806033a09e8..2dbc193d2cb2f 100644 --- a/test/numbers.jl +++ b/test/numbers.jl @@ -1827,3 +1827,6 @@ ndigf(n) = float64(log(float32(n))) # issue #7911 @test sum([int128(1) int128(2)]) == int128(3) +let x = big(-0.0) + @test signbit(x) && !signbit(abs(x)) +end