Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deprecate functions inf and nan #8776

Merged
merged 1 commit into from
Oct 23, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions base/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -338,12 +338,12 @@ function exp(z::Complex)
if isnan(zr)
Complex(zr, zi==0 ? zi : zr)
elseif !isfinite(zi)
if zr == inf(zr)
Complex(-zr, nan(zr))
elseif zr == -inf(zr)
if zr == Inf
Complex(-zr, oftype(zr,NaN))
elseif zr == -Inf
Complex(-zero(zr), copysign(zero(zi), zi))
else
Complex(nan(zr), nan(zi))
Complex(oftype(zr,NaN), oftype(zi,NaN))
end
else
er = exp(zr)
Expand All @@ -360,12 +360,12 @@ function expm1(z::Complex)
if isnan(zr)
Complex(zr, zi==0 ? zi : zr)
elseif !isfinite(zi)
if zr == inf(zr)
Complex(-zr, nan(zr))
elseif zr == -inf(zr)
if zr == Inf
Complex(-zr, oftype(zr,NaN))
elseif zr == -Inf
Complex(-one(zr), copysign(zero(zi), zi))
else
Complex(nan(zr), nan(zi))
Complex(oftype(zr,NaN), oftype(zi,NaN))
end
else
erm1 = expm1(zr)
Expand All @@ -391,9 +391,9 @@ function log1p{T}(z::Complex{T})
elseif isnan(zr)
Complex(zr, zr)
elseif isfinite(zi)
Complex(inf(T), copysign(zr > 0 ? zero(T) : convert(T, pi), zi))
Complex(T(Inf), copysign(zr > 0 ? zero(T) : convert(T, pi), zi))
else
Complex(inf(T), nan(T))
Complex(T(Inf), T(NaN))
end
end

Expand Down Expand Up @@ -636,7 +636,7 @@ function acosh(z::Complex)
return Complex(oftype(zr, NaN), oftype(zi, NaN))
end
elseif zr==-Inf && zi===-0.0 #Edge case is wrong - WHY?
return Complex(inf(zr), oftype(zi, -pi))
return Complex(oftype(zr,Inf), oftype(zi, -pi))
end
ξ = asinh(real(sqrt(conj(z-1))*sqrt(z+1)))
η = 2atan2(imag(sqrt(z-1)),real(sqrt(z+1)))
Expand Down
5 changes: 5 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,8 @@ end
@deprecate itrunc{T<:Integer}(::Type{T}, n::Integer) (n % T)

@deprecate oftype{T}(::Type{T},c) convert(T,c)

@deprecate inf(x::FloatingPoint) oftype(x,Inf)
@deprecate nan(x::FloatingPoint) oftype(x,NaN)
@deprecate inf{T<:FloatingPoint}(::Type{T}) convert(T,Inf)
@deprecate nan{T<:FloatingPoint}(::Type{T}) convert(T,NaN)
2 changes: 0 additions & 2 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,6 @@ export
iceil,
ifloor,
imag,
inf,
int,
int128,
int16,
Expand Down Expand Up @@ -402,7 +401,6 @@ export
mod1,
modf,
mod2pi,
nan,
nextfloat,
nextpow,
nextpow2,
Expand Down
11 changes: 1 addition & 10 deletions base/float.jl
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,6 @@ nextfloat(x::FloatingPoint) = nextfloat(x,1)
prevfloat(x::FloatingPoint) = nextfloat(x,-1)

@eval begin
inf(::Type{Float16}) = $Inf16
nan(::Type{Float16}) = $NaN16
inf(::Type{Float32}) = $Inf32
nan(::Type{Float32}) = $NaN32
inf(::Type{Float64}) = $Inf
nan(::Type{Float64}) = $NaN
inf{T<:FloatingPoint}(x::T) = inf(T)
nan{T<:FloatingPoint}(x::T) = nan(T)

issubnormal(x::Float32) = (abs(x) < $(box(Float32,unbox(Uint32,0x00800000)))) & (x!=0)
issubnormal(x::Float64) = (abs(x) < $(box(Float64,unbox(Uint64,0x0010000000000000)))) & (x!=0)

Expand All @@ -285,7 +276,7 @@ prevfloat(x::FloatingPoint) = nextfloat(x,-1)
realmin() = realmin(Float64)
realmax() = realmax(Float64)

eps(x::FloatingPoint) = isfinite(x) ? abs(x) >= realmin(x) ? ldexp(eps(typeof(x)),exponent(x)) : nextfloat(zero(x)) : nan(x)
eps(x::FloatingPoint) = isfinite(x) ? abs(x) >= realmin(x) ? ldexp(eps(typeof(x)),exponent(x)) : nextfloat(zero(x)) : oftype(x,NaN)
eps(::Type{Float16}) = $(box(Float16,unbox(Uint16,0x1400)))
eps(::Type{Float32}) = $(box(Float32,unbox(Uint32,0x34000000)))
eps(::Type{Float64}) = $(box(Float64,unbox(Uint64,0x3cb0000000000000)))
Expand Down
2 changes: 1 addition & 1 deletion base/linalg/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ function cond(A::StridedMatrix, p::Real=2)
if p == 2
v = svdvals(A)
maxv = maximum(v)
return maxv == 0.0 ? inf(typeof(real(A[1,1]))) : maxv / minimum(v)
return maxv == 0.0 ? oftype(real(A[1,1]),Inf) : maxv / minimum(v)
elseif p == 1 || p == Inf
chksquare(A)
return cond(lufact(A), p)
Expand Down
9 changes: 3 additions & 6 deletions base/mpfr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import
gamma, lgamma, digamma, erf, erfc, zeta, eta, log1p, airyai, iceil, ifloor,
itrunc, eps, signbit, sin, cos, tan, sec, csc, cot, acos, asin, atan,
cosh, sinh, tanh, sech, csch, coth, acosh, asinh, atanh, atan2,
serialize, deserialize, inf, nan, cbrt, typemax, typemin,
serialize, deserialize, cbrt, typemax, typemin,
realmin, realmax, get_rounding, set_rounding, maxintfloat, widen,
significand, frexp

Expand Down Expand Up @@ -654,10 +654,7 @@ end

isfinite(x::BigFloat) = !isinf(x) && !isnan(x)

@eval inf(::Type{BigFloat}) = $(BigFloat(Inf))
@eval nan(::Type{BigFloat}) = $(BigFloat(NaN))

typemax(::Type{BigFloat}) = inf(BigFloat)
@eval typemax(::Type{BigFloat}) = $(BigFloat( Inf))
@eval typemin(::Type{BigFloat}) = $(BigFloat(-Inf))

function nextfloat(x::BigFloat)
Expand All @@ -679,7 +676,7 @@ end
eps(::Type{BigFloat}) = nextfloat(BigFloat(1)) - BigFloat(1)

realmin(::Type{BigFloat}) = nextfloat(zero(BigFloat))
realmax(::Type{BigFloat}) = prevfloat(inf(BigFloat))
realmax(::Type{BigFloat}) = prevfloat(BigFloat(Inf))

function with_bigfloat_precision(f::Function, precision::Integer)
old_precision = get_bigfloat_precision()
Expand Down
12 changes: 6 additions & 6 deletions base/special/erf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ function erfinv(x::Float64)
a = abs(x)
if a >= 1.0
if x == 1.0
return inf(Float64)
return Inf
elseif x == -1.0
return -inf(Float64)
return -Inf
end
throw(DomainError())
elseif a <= 0.75 # Table 17 in Blair et al.
Expand Down Expand Up @@ -98,9 +98,9 @@ function erfinv(x::Float32)
a = abs(x)
if a >= 1.0f0
if x == 1.0f0
return inf(Float32)
return Inf32
elseif x == -1.0f0
return -inf(Float32)
return -Inf32
end
throw(DomainError())
elseif a <= 0.75f0 # Table 10 in Blair et al.
Expand Down Expand Up @@ -147,7 +147,7 @@ function erfcinv(y::Float64)
return erfinv(1.0 - y)
elseif y <= 0.0
if y == 0.0
return inf(Float64)
return Inf
end
throw(DomainError())
elseif y >= 1e-100 # Table 57 in Blair et al.
Expand Down Expand Up @@ -199,7 +199,7 @@ function erfcinv(y::Float32)
return erfinv(1.0f0 - y)
elseif y <= 0.0f0
if y == 0.0f0
return inf(Float32)
return Inf32
end
throw(DomainError())
else # Table 50 in Blair et al.
Expand Down
8 changes: 4 additions & 4 deletions base/special/trig.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function sinpi(x::Real)
if isinf(x)
return throw(DomainError())
elseif isnan(x)
return nan(x)
return oftype(x,NaN)
end

rx = copysign(rem(x,2),x)
Expand Down Expand Up @@ -131,7 +131,7 @@ function cospi(x::Real)
if isinf(x)
return throw(DomainError())
elseif isnan(x)
return nan(x)
return oftype(x,NaN)
end

rx = abs(float(rem(x,2)))
Expand Down Expand Up @@ -236,7 +236,7 @@ function sind(x::Real)
if isinf(x)
return throw(DomainError())
elseif isnan(x)
return nan(x)
return oftype(x,NaN)
end

rx = copysign(float(rem(x,360)),x)
Expand Down Expand Up @@ -268,7 +268,7 @@ function cosd(x::Real)
if isinf(x)
return throw(DomainError())
elseif isnan(x)
return nan(x)
return oftype(x,NaN)
end

rx = abs(float(rem(x,360)))
Expand Down
4 changes: 2 additions & 2 deletions base/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ function test_approx_eq(va, vb, Eps, astr, bstr)
end
end

array_eps{T}(a::AbstractArray{Complex{T}}) = eps(float(maximum(x->(isfinite(x) ? abs(x) : nan(T)), a)))
array_eps(a) = eps(float(maximum(x->(isfinite(x) ? abs(x) : nan(x)), a)))
array_eps{T}(a::AbstractArray{Complex{T}}) = eps(float(maximum(x->(isfinite(x) ? abs(x) : T(NaN)), a)))
array_eps(a) = eps(float(maximum(x->(isfinite(x) ? abs(x) : oftype(x,NaN)), a)))

test_approx_eq(va, vb, astr, bstr) =
test_approx_eq(va, vb, 1E4*length(va)*max(array_eps(va), array_eps(vb)), astr, bstr)
Expand Down
2 changes: 1 addition & 1 deletion test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ let
@test x == 11
x = get(A, (4,4), -12)
@test x == -12
X = get(A, -5:5, nan(Float32))
X = get(A, -5:5, NaN32)
@test eltype(X) == Float32
@test isnan(X) == [trues(6),falses(5)]
@test X[7:11] == [1:5]
Expand Down