From 99fa5976ff4af62c87682b07a86b96ee0f76a6b3 Mon Sep 17 00:00:00 2001 From: Stefan Karpinski Date: Wed, 15 Jul 2015 10:21:29 -0400 Subject: [PATCH 1/2] rename: FloatingPoint => AbstractFloat --- NEWS.md | 2 +- base/abstractarray.jl | 4 +- base/abstractarraymath.jl | 4 +- base/array.jl | 2 +- base/arraymath.jl | 2 +- base/bool.jl | 4 +- base/boot.jl | 10 ++-- base/complex.jl | 32 ++++++------ base/datafmt.jl | 2 +- base/deprecated.jl | 12 ++--- base/dft.jl | 4 +- base/float.jl | 68 ++++++++++++------------- base/floatfuncs.jl | 24 ++++----- base/grisu.jl | 14 ++--- base/grisu/float.jl | 12 ++--- base/irrationals.jl | 8 +-- base/linalg/givens.jl | 4 +- base/linalg/lapack.jl | 4 +- base/linalg/lu.jl | 2 +- base/math.jl | 24 ++++----- base/mpfr.jl | 12 ++--- base/operators.jl | 16 +++--- base/parse.jl | 2 +- base/quadgk.jl | 8 +-- base/range.jl | 32 ++++++------ base/rational.jl | 22 ++++---- base/reduce.jl | 2 +- base/rounding.jl | 10 ++-- base/sparse/sparsematrix.jl | 18 +++---- base/sparse/spqr.jl | 2 +- base/special/bessel.jl | 24 ++++----- base/special/trig.jl | 4 +- base/statistics.jl | 6 +-- base/sysimg.jl | 2 +- contrib/julia-mode.el | 2 +- contrib/julia.hrc | 2 +- contrib/julia.xml | 2 +- contrib/windows/julia.rc | 2 +- doc/devdocs/reflection.rst | 4 +- doc/devdocs/types.rst | 4 +- doc/helpdb.jl | 14 ++--- doc/manual/conversion-and-promotion.rst | 20 ++++---- doc/manual/faq.rst | 16 +++--- doc/manual/methods.rst | 12 ++--- doc/manual/types.rst | 22 ++++---- doc/stdlib/base.rst | 2 +- doc/stdlib/math.rst | 4 +- doc/stdlib/numbers.rst | 6 +-- src/init.c | 2 +- test/char.jl | 2 +- test/core.jl | 6 +-- test/linalg/dense.jl | 2 +- test/linalg/generic.jl | 2 +- test/linalg2.jl | 2 +- test/mpfr.jl | 4 +- test/perf/arrayalloc/lucompletepiv.py | 2 +- test/random.jl | 2 +- test/ranges.jl | 4 +- test/reducedim.jl | 2 +- test/tuple.jl | 2 +- test/unicode.jl | 2 +- 61 files changed, 272 insertions(+), 272 deletions(-) diff --git a/NEWS.md b/NEWS.md index 5e7d433885bf3..806f9b5155fa7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -382,7 +382,7 @@ Deprecated or removed end ``` - * indexing with Reals that are not subtypes of Integers (Rationals, FloatingPoint, etc.) has been deprecated ([#10458]). + * indexing with Reals that are not subtypes of Integers (Rationals, AbstractFloat, etc.) has been deprecated ([#10458]). * `push!(A)` has been deprecated, use `append!` instead of splatting arguments to `push!` ([#10400]). diff --git a/base/abstractarray.jl b/base/abstractarray.jl index 4a1c60ba30286..bc7c6315e88b4 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -424,8 +424,8 @@ map(::Type{Unsigned}, a::Array) = map!(Unsigned, similar(a,typeof(Unsigned(one(e map{T<:Real}(::Type{T}, r::StepRange) = T(r.start):T(r.step):T(last(r)) map{T<:Real}(::Type{T}, r::UnitRange) = T(r.start):T(last(r)) -map{T<:FloatingPoint}(::Type{T}, r::FloatRange) = FloatRange(T(r.start), T(r.step), r.len, T(r.divisor)) -function map{T<:FloatingPoint}(::Type{T}, r::LinSpace) +map{T<:AbstractFloat}(::Type{T}, r::FloatRange) = FloatRange(T(r.start), T(r.step), r.len, T(r.divisor)) +function map{T<:AbstractFloat}(::Type{T}, r::LinSpace) new_len = T(r.len) new_len == r.len || error("$r: too long for $T") LinSpace(T(r.start), T(r.stop), new_len, T(r.divisor)) diff --git a/base/abstractarraymath.jl b/base/abstractarraymath.jl index 6e064ea4541f8..7fc7a868187a3 100644 --- a/base/abstractarraymath.jl +++ b/base/abstractarraymath.jl @@ -106,7 +106,7 @@ function circshift{T,N}(a::AbstractArray{T,N}, shiftamts) end # Uses K-B-N summation -function cumsum_kbn{T<:FloatingPoint}(v::AbstractVector{T}) +function cumsum_kbn{T<:AbstractFloat}(v::AbstractVector{T}) n = length(v) r = similar(v, n) if n == 0; return r; end @@ -128,7 +128,7 @@ function cumsum_kbn{T<:FloatingPoint}(v::AbstractVector{T}) end # Uses K-B-N summation -function cumsum_kbn{T<:FloatingPoint}(A::AbstractArray{T}, axis::Integer=1) +function cumsum_kbn{T<:AbstractFloat}(A::AbstractArray{T}, axis::Integer=1) dimsA = size(A) ndimsA = ndims(A) axis_size = dimsA[axis] diff --git a/base/array.jl b/base/array.jl index 05a70621bec62..1b261a4886fe5 100644 --- a/base/array.jl +++ b/base/array.jl @@ -182,7 +182,7 @@ function fill!(a::Union{Array{UInt8}, Array{Int8}}, x::Integer) return a end -function fill!{T<:Union{Integer,FloatingPoint}}(a::Array{T}, x) +function fill!{T<:Union{Integer,AbstractFloat}}(a::Array{T}, x) # note: checking bit pattern xT = convert(T,x) if isbits(T) && nfields(T)==0 && diff --git a/base/arraymath.jl b/base/arraymath.jl index 1b542f67e01cb..caa52d79387b5 100644 --- a/base/arraymath.jl +++ b/base/arraymath.jl @@ -39,7 +39,7 @@ end ## Binary arithmetic operators ## promote_array_type{Scalar, Arry}(F, ::Type{Scalar}, ::Type{Arry}) = promote_op(F, Scalar, Arry) -promote_array_type{S<:Real, A<:FloatingPoint}(F, ::Type{S}, ::Type{A}) = A +promote_array_type{S<:Real, A<:AbstractFloat}(F, ::Type{S}, ::Type{A}) = A promote_array_type{S<:Integer, A<:Integer}(F, ::Type{S}, ::Type{A}) = A promote_array_type{S<:Integer}(F, ::Type{S}, ::Type{Bool}) = S diff --git a/base/bool.jl b/base/bool.jl index 677292dcb95a2..95df1e3494cb3 100644 --- a/base/bool.jl +++ b/base/bool.jl @@ -39,11 +39,11 @@ abs2(x::Bool) = x ^(x::Bool, y::Bool) = x | !y ^(x::Integer, y::Bool) = ifelse(y, x, one(x)) -function +{T<:FloatingPoint}(x::Bool, y::T) +function +{T<:AbstractFloat}(x::Bool, y::T) ifelse(x, one(promote_type(Bool,T)) + convert(promote_type(Bool,T),y), convert(promote_type(Bool,T),y)) end -+(y::FloatingPoint, x::Bool) = x + y ++(y::AbstractFloat, x::Bool) = x + y function *{T<:Number}(x::Bool, y::T) ifelse(x, convert(promote_type(Bool,T),y), diff --git a/base/boot.jl b/base/boot.jl index f96475c39810d..ea8c0a4398030 100644 --- a/base/boot.jl +++ b/base/boot.jl @@ -133,7 +133,7 @@ export Module, Symbol, Task, Array, WeakRef, # numeric types Number, Real, Integer, Bool, Ref, Ptr, - FloatingPoint, Float16, Float32, Float64, + AbstractFloat, Float16, Float32, Float64, Signed, Int, Int8, Int16, Int32, Int64, Int128, Unsigned, UInt, UInt8, UInt16, UInt32, UInt64, UInt128, # string types @@ -180,14 +180,14 @@ const (===) = is abstract Number abstract Real <: Number -abstract FloatingPoint <: Real +abstract AbstractFloat <: Real abstract Integer <: Real abstract Signed <: Integer abstract Unsigned <: Integer -bitstype 16 Float16 <: FloatingPoint -bitstype 32 Float32 <: FloatingPoint -bitstype 64 Float64 <: FloatingPoint +bitstype 16 Float16 <: AbstractFloat +bitstype 32 Float32 <: AbstractFloat +bitstype 64 Float64 <: AbstractFloat bitstype 8 Bool <: Integer bitstype 32 Char diff --git a/base/complex.jl b/base/complex.jl index eda1a60f82894..d254b6d799e0f 100644 --- a/base/complex.jl +++ b/base/complex.jl @@ -59,7 +59,7 @@ function complex_show(io::IO, z::Complex, compact::Bool) print(io, compact ? "+" : " + ") end compact ? showcompact(io, i) : show(io, i) - if !(isa(i,Integer) && !isa(i,Bool) || isa(i,FloatingPoint) && isfinite(i)) + if !(isa(i,Integer) && !isa(i,Bool) || isa(i,AbstractFloat) && isfinite(i)) print(io, "*") end print(io, "im") @@ -227,7 +227,7 @@ function inv(w::Complex128) return Complex128(p*s,q*s) # undo scaling end -function ssqs{T<:FloatingPoint}(x::T, y::T) +function ssqs{T<:AbstractFloat}(x::T, y::T) k::Int = 0 ρ = x*x + y*y if !isfinite(ρ) && (isinf(x) || isinf(y)) @@ -241,7 +241,7 @@ function ssqs{T<:FloatingPoint}(x::T, y::T) ρ, k end -function sqrt{T<:FloatingPoint}(z::Complex{T}) +function sqrt{T<:AbstractFloat}(z::Complex{T}) x, y = reim(z) if x==y==0 return Complex(zero(x),y) @@ -291,7 +291,7 @@ end angle(z::Complex) = atan2(imag(z), real(z)) -function log{T<:FloatingPoint}(z::Complex{T}) +function log{T<:AbstractFloat}(z::Complex{T}) const T1::T = 1.25 const T2::T = 3 const ln2::T = log(convert(T,2)) #0.6931471805599453 @@ -405,7 +405,7 @@ function log1p{T}(z::Complex{T}) end end -function ^{T<:FloatingPoint}(z::Complex{T}, p::Complex{T}) +function ^{T<:AbstractFloat}(z::Complex{T}, p::Complex{T}) if p==2 #square zr, zi = reim(z) x = (zr-zi)*(zr+zi) @@ -513,10 +513,10 @@ end ^(z::Complex, n::Bool) = n ? z : one(z) ^(z::Complex, n::Integer) = z^Complex(n) -^{T<:FloatingPoint}(z::Complex{T}, n::Bool) = n ? z : one(z) # to resolve ambiguity +^{T<:AbstractFloat}(z::Complex{T}, n::Bool) = n ? z : one(z) # to resolve ambiguity ^{T<:Integer}(z::Complex{T}, n::Bool) = n ? z : one(z) # to resolve ambiguity -^{T<:FloatingPoint}(z::Complex{T}, n::Integer) = +^{T<:AbstractFloat}(z::Complex{T}, n::Integer) = n>=0 ? power_by_squaring(z,n) : power_by_squaring(inv(z),-n) ^{T<:Integer}(z::Complex{T}, n::Integer) = power_by_squaring(z,n) # DomainError for n<0 @@ -566,7 +566,7 @@ function asin(z::Complex) Complex(ξ,η) end -function acos{T<:FloatingPoint}(z::Complex{T}) +function acos{T<:AbstractFloat}(z::Complex{T}) zr, zi = reim(z) if isnan(zr) if isinf(zi) return Complex(zr, -zi) @@ -607,7 +607,7 @@ function cosh(z::Complex) cos(Complex(-zi,zr)) end -function tanh{T<:FloatingPoint}(z::Complex{T}) +function tanh{T<:AbstractFloat}(z::Complex{T}) const Ω = prevfloat(typemax(T)) ξ, η = reim(z) if isnan(ξ) && η==0 return Complex(ξ, η) end @@ -652,7 +652,7 @@ function acosh(z::Complex) Complex(ξ, η) end -function atanh{T<:FloatingPoint}(z::Complex{T}) +function atanh{T<:AbstractFloat}(z::Complex{T}) const Ω = prevfloat(typemax(T)) const θ = sqrt(Ω)/4 const ρ = 1/θ @@ -704,13 +704,13 @@ end #Requires two different RoundingModes for the real and imaginary components if WORD_SIZE==32 -function round{T<:FloatingPoint, MR, MI}(z::Complex{T}, ::RoundingMode{MR}, ::RoundingMode{MI}) +function round{T<:AbstractFloat, MR, MI}(z::Complex{T}, ::RoundingMode{MR}, ::RoundingMode{MI}) Complex((round(real(z), RoundingMode{MR}()), round(imag(z), RoundingMode{MI}()))...) end round(z::Complex) = Complex((round(real(z)), round(imag(z)))...) else -function round{T<:FloatingPoint, MR, MI}(z::Complex{T}, ::RoundingMode{MR}, ::RoundingMode{MI}) +function round{T<:AbstractFloat, MR, MI}(z::Complex{T}, ::RoundingMode{MR}, ::RoundingMode{MI}) Complex(round(real(z), RoundingMode{MR}()), round(imag(z), RoundingMode{MI}())) end @@ -724,11 +724,11 @@ function round(z::Complex, digits::Integer, base::Integer=10) round(imag(z), digits, base)) end -float{T<:FloatingPoint}(z::Complex{T}) = z +float{T<:AbstractFloat}(z::Complex{T}) = z float(z::Complex) = Complex(float(real(z)), float(imag(z))) @vectorize_1arg Complex float -big{T<:FloatingPoint}(z::Complex{T}) = Complex{BigFloat}(z) +big{T<:AbstractFloat}(z::Complex{T}) = Complex{BigFloat}(z) big{T<:Integer}(z::Complex{T}) = Complex{BigInt}(z) ## Array operations on complex numbers ## @@ -743,11 +743,11 @@ function complex{T}(A::AbstractArray{T}) end big{T<:Integer,N}(A::AbstractArray{Complex{T},N}) = convert(AbstractArray{Complex{BigInt},N}, A) -big{T<:FloatingPoint,N}(A::AbstractArray{Complex{T},N}) = convert(AbstractArray{Complex{BigFloat},N}, A) +big{T<:AbstractFloat,N}(A::AbstractArray{Complex{T},N}) = convert(AbstractArray{Complex{BigFloat},N}, A) ## promotion to complex ## -promote_array_type{S<:Union{Complex, Real}, AT<:FloatingPoint}(F, ::Type{S}, ::Type{Complex{AT}}) = Complex{AT} +promote_array_type{S<:Union{Complex, Real}, AT<:AbstractFloat}(F, ::Type{S}, ::Type{Complex{AT}}) = Complex{AT} function complex{S<:Real,T<:Real}(A::Array{S}, B::Array{T}) if size(A) != size(B); throw(DimensionMismatch()); end diff --git a/base/datafmt.jl b/base/datafmt.jl index d057e6fb20089..fc7fa4e413f84 100644 --- a/base/datafmt.jl +++ b/base/datafmt.jl @@ -522,7 +522,7 @@ readcsv(io; opts...) = readdlm(io, ','; opts...) readcsv(io, T::Type; opts...) = readdlm(io, ',', T; opts...) # todo: keyword argument for # of digits to print -writedlm_cell(io::IO, elt::FloatingPoint, dlm, quotes) = print_shortest(io, elt) +writedlm_cell(io::IO, elt::AbstractFloat, dlm, quotes) = print_shortest(io, elt) function writedlm_cell{T}(io::IO, elt::AbstractString, dlm::T, quotes::Bool) if quotes && !isempty(elt) && (('"' in elt) || ('\n' in elt) || ((T <: Char) ? (dlm in elt) : contains(elt, dlm))) print(io, '"', replace(elt, r"\"", "\"\""), '"') diff --git a/base/deprecated.jl b/base/deprecated.jl index f2a3960ad2697..41ffaed5daf42 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -135,10 +135,10 @@ end @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) +@deprecate inf(x::AbstractFloat) oftype(x,Inf) +@deprecate nan(x::AbstractFloat) oftype(x,NaN) +@deprecate inf{T<:AbstractFloat}(::Type{T}) convert(T,Inf) +@deprecate nan{T<:AbstractFloat}(::Type{T}) convert(T,NaN) export String const String = AbstractString @@ -281,7 +281,7 @@ end @deprecate bool(x::Number) x!=0 @deprecate char(x) Char(x) -@deprecate char(x::FloatingPoint) Char(round(UInt32,x)) +@deprecate char(x::AbstractFloat) Char(round(UInt32,x)) @deprecate integer(x::Char) Int(x) @deprecate complex128(r::Real, i::Real) Complex128(r, i) @@ -323,7 +323,7 @@ for (f,t) in ((:uint8,:UInt8), (:uint16,:UInt16), (:uint32,:UInt32), (:uint64,:U (:int128,:Int128), (:uint128,:UInt128), (:signed,:Int), (:unsigned,:UInt), (:integer,:Int), (:int,:Int), (:uint,:UInt)) @eval begin - @deprecate ($f)(x::FloatingPoint) round($t,x) + @deprecate ($f)(x::AbstractFloat) round($t,x) @deprecate ($f)(x::Rational) round($t,x) end end diff --git a/base/dft.jl b/base/dft.jl index fcff7ffafdcef..0288fa6798ae6 100644 --- a/base/dft.jl +++ b/base/dft.jl @@ -20,12 +20,12 @@ export fft, ifft, bfft, fft!, ifft!, bfft!, plan_fft, plan_ifft, plan_bfft, plan_fft!, plan_ifft!, plan_bfft!, rfft, irfft, brfft, plan_rfft, plan_irfft, plan_brfft -complexfloat{T<:FloatingPoint}(x::AbstractArray{Complex{T}}) = x +complexfloat{T<:AbstractFloat}(x::AbstractArray{Complex{T}}) = x # return an Array, rather than similar(x), to avoid an extra copy for FFTW # (which only works on StridedArray types). complexfloat{T<:Complex}(x::AbstractArray{T}) = copy!(Array(typeof(float(one(T))), size(x)), x) -complexfloat{T<:FloatingPoint}(x::AbstractArray{T}) = copy!(Array(typeof(complex(one(T))), size(x)), x) +complexfloat{T<:AbstractFloat}(x::AbstractArray{T}) = copy!(Array(typeof(complex(one(T))), size(x)), x) complexfloat{T<:Real}(x::AbstractArray{T}) = copy!(Array(typeof(complex(float(one(T)))), size(x)), x) # implementations only need to provide plan_X(x, region) diff --git a/base/float.jl b/base/float.jl index 0f950bb71e2b0..8f681755f0645 100644 --- a/base/float.jl +++ b/base/float.jl @@ -106,19 +106,19 @@ convert(::Type{Float32}, x::Float64) = box(Float32,fptrunc(Float32,unbox(Float64 convert(::Type{Float64}, x::Float16) = convert(Float64, convert(Float32,x)) convert(::Type{Float64}, x::Float32) = box(Float64,fpext(Float64,unbox(Float32,x))) -convert(::Type{FloatingPoint}, x::Bool) = convert(Float64, x) -convert(::Type{FloatingPoint}, x::Int8) = convert(Float64, x) -convert(::Type{FloatingPoint}, x::Int16) = convert(Float64, x) -convert(::Type{FloatingPoint}, x::Int32) = convert(Float64, x) -convert(::Type{FloatingPoint}, x::Int64) = convert(Float64, x) # LOSSY -convert(::Type{FloatingPoint}, x::Int128) = convert(Float64, x) # LOSSY -convert(::Type{FloatingPoint}, x::UInt8) = convert(Float64, x) -convert(::Type{FloatingPoint}, x::UInt16) = convert(Float64, x) -convert(::Type{FloatingPoint}, x::UInt32) = convert(Float64, x) -convert(::Type{FloatingPoint}, x::UInt64) = convert(Float64, x) # LOSSY -convert(::Type{FloatingPoint}, x::UInt128) = convert(Float64, x) # LOSSY - -float(x) = convert(FloatingPoint, x) +convert(::Type{AbstractFloat}, x::Bool) = convert(Float64, x) +convert(::Type{AbstractFloat}, x::Int8) = convert(Float64, x) +convert(::Type{AbstractFloat}, x::Int16) = convert(Float64, x) +convert(::Type{AbstractFloat}, x::Int32) = convert(Float64, x) +convert(::Type{AbstractFloat}, x::Int64) = convert(Float64, x) # LOSSY +convert(::Type{AbstractFloat}, x::Int128) = convert(Float64, x) # LOSSY +convert(::Type{AbstractFloat}, x::UInt8) = convert(Float64, x) +convert(::Type{AbstractFloat}, x::UInt16) = convert(Float64, x) +convert(::Type{AbstractFloat}, x::UInt32) = convert(Float64, x) +convert(::Type{AbstractFloat}, x::UInt64) = convert(Float64, x) # LOSSY +convert(::Type{AbstractFloat}, x::UInt128) = convert(Float64, x) # LOSSY + +float(x) = convert(AbstractFloat, x) for Ti in (Int8, Int16, Int32, Int64) @eval begin @@ -172,9 +172,9 @@ trunc(::Type{Integer}, x::Float32) = trunc(Int,x) trunc(::Type{Integer}, x::Float64) = trunc(Int,x) # fallbacks -floor{T<:Integer}(::Type{T}, x::FloatingPoint) = trunc(T,floor(x)) -ceil{ T<:Integer}(::Type{T}, x::FloatingPoint) = trunc(T,ceil(x)) -round{T<:Integer}(::Type{T}, x::FloatingPoint) = trunc(T,round(x)) +floor{T<:Integer}(::Type{T}, x::AbstractFloat) = trunc(T,floor(x)) +ceil{ T<:Integer}(::Type{T}, x::AbstractFloat) = trunc(T,ceil(x)) +round{T<:Integer}(::Type{T}, x::AbstractFloat) = trunc(T,round(x)) trunc(x::Float64) = box(Float64,trunc_llvm(unbox(Float64,x))) trunc(x::Float32) = box(Float32,trunc_llvm(unbox(Float32,x))) @@ -218,9 +218,9 @@ muladd(x::Float64, y::Float64, z::Float64) = box(Float64,muladd_float(unbox(Floa rem(x::Float32, y::Float32) = box(Float32,rem_float(unbox(Float32,x),unbox(Float32,y))) rem(x::Float64, y::Float64) = box(Float64,rem_float(unbox(Float64,x),unbox(Float64,y))) -cld{T<:FloatingPoint}(x::T, y::T) = -fld(-x,y) +cld{T<:AbstractFloat}(x::T, y::T) = -fld(-x,y) -function mod{T<:FloatingPoint}(x::T, y::T) +function mod{T<:AbstractFloat}(x::T, y::T) r = rem(x,y) if r == 0 copysign(r,y) @@ -246,17 +246,17 @@ isequal(x::Float64, y::Float64) = fpiseq(unbox(Float64,x),unbox(Float64,y)) isless( x::Float32, y::Float32) = fpislt(unbox(Float32,x),unbox(Float32,y)) isless( x::Float64, y::Float64) = fpislt(unbox(Float64,x),unbox(Float64,y)) -function cmp(x::FloatingPoint, y::FloatingPoint) +function cmp(x::AbstractFloat, y::AbstractFloat) (isnan(x) || isnan(y)) && throw(DomainError()) ifelse(xy, 1, 0)) end -function cmp(x::Real, y::FloatingPoint) +function cmp(x::Real, y::AbstractFloat) isnan(y) && throw(DomainError()) ifelse(xy, 1, 0)) end -function cmp(x::FloatingPoint, y::Real) +function cmp(x::AbstractFloat, y::Real) isnan(x) && throw(DomainError()) ifelse(xy, 1, 0)) end @@ -303,10 +303,10 @@ end abs(x::Float64) = box(Float64,abs_float(unbox(Float64,x))) abs(x::Float32) = box(Float32,abs_float(unbox(Float32,x))) -isnan(x::FloatingPoint) = x != x +isnan(x::AbstractFloat) = x != x isnan(x::Real) = false -isfinite(x::FloatingPoint) = x - x == 0 +isfinite(x::AbstractFloat) = x - x == 0 isfinite(x::Real) = decompose(x)[3] != 0 isfinite(x::Integer) = true @@ -328,7 +328,7 @@ hash(x::Float32, h::UInt) = hash(Float64(x), h) precision(::Type{Float16}) = 11 precision(::Type{Float32}) = 24 precision(::Type{Float64}) = 53 -precision{T<:FloatingPoint}(::T) = precision(T) +precision{T<:AbstractFloat}(::T) = precision(T) function float_lex_order(f::Integer, delta::Integer) # convert from signed magnitude to 2's complement and back @@ -347,8 +347,8 @@ nextfloat(x::Float32, i::Integer) = (isinf(x)&&sign(x)==sign(i)) ? x : reinterpret(Float32,float_lex_order(reinterpret(Int32,x), i)) nextfloat(x::Float64, i::Integer) = (isinf(x)&&sign(x)==sign(i)) ? x : reinterpret(Float64,float_lex_order(reinterpret(Int64,x), i)) -nextfloat(x::FloatingPoint) = nextfloat(x,1) -prevfloat(x::FloatingPoint) = nextfloat(x,-1) +nextfloat(x::AbstractFloat) = nextfloat(x,1) +prevfloat(x::AbstractFloat) = nextfloat(x,-1) for Ti in (Int8, Int16, Int32, Int64, Int128, UInt8, UInt16, UInt32, UInt64, UInt128) for Tf in (Float32, Float64) @@ -387,12 +387,12 @@ end realmax(::Type{Float16}) = $(box(Float16,unbox(UInt16,0x7bff))) realmax(::Type{Float32}) = $(box(Float32,unbox(UInt32,0x7f7fffff))) realmax(::Type{Float64}) = $(box(Float64,unbox(UInt64,0x7fefffffffffffff))) - realmin{T<:FloatingPoint}(x::T) = realmin(T) - realmax{T<:FloatingPoint}(x::T) = realmax(T) + realmin{T<:AbstractFloat}(x::T) = realmin(T) + realmax{T<:AbstractFloat}(x::T) = realmax(T) realmin() = realmin(Float64) realmax() = realmax(Float64) - eps(x::FloatingPoint) = isfinite(x) ? abs(x) >= realmin(x) ? ldexp(eps(typeof(x)),exponent(x)) : nextfloat(zero(x)) : oftype(x,NaN) + eps(x::AbstractFloat) = 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))) @@ -449,13 +449,13 @@ exponent_one(::Type{Float32}) = 0x3f80_0000 exponent_half(::Type{Float32}) = 0x3f00_0000 significand_mask(::Type{Float32}) = 0x007f_ffff -significand_bits{T<:FloatingPoint}(::Type{T}) = trailing_ones(significand_mask(T)) -exponent_bits{T<:FloatingPoint}(::Type{T}) = sizeof(T)*8 - significand_bits(T) - 1 -exponent_bias{T<:FloatingPoint}(::Type{T}) = Int(exponent_one(T) >> significand_bits(T)) +significand_bits{T<:AbstractFloat}(::Type{T}) = trailing_ones(significand_mask(T)) +exponent_bits{T<:AbstractFloat}(::Type{T}) = sizeof(T)*8 - significand_bits(T) - 1 +exponent_bias{T<:AbstractFloat}(::Type{T}) = Int(exponent_one(T) >> significand_bits(T)) ## Array operations on floating point numbers ## -float{T<:FloatingPoint}(A::AbstractArray{T}) = A +float{T<:AbstractFloat}(A::AbstractArray{T}) = A function float{T}(A::AbstractArray{T}) if !isleaftype(T) @@ -477,5 +477,5 @@ for fn in (:float,:big) end end -big{T<:FloatingPoint,N}(x::AbstractArray{T,N}) = convert(AbstractArray{BigFloat,N}, x) +big{T<:AbstractFloat,N}(x::AbstractArray{T,N}) = convert(AbstractArray{BigFloat,N}, x) big{T<:Integer,N}(x::AbstractArray{T,N}) = convert(AbstractArray{BigInt,N}, x) diff --git a/base/floatfuncs.jl b/base/floatfuncs.jl index 6b307ae678335..3dfb749a17e4e 100644 --- a/base/floatfuncs.jl +++ b/base/floatfuncs.jl @@ -21,10 +21,10 @@ signbit(x::Float16) = signbit(reinterpret(Int16,x)) maxintfloat(::Type{Float64}) = 9007199254740992. maxintfloat(::Type{Float32}) = Float32(16777216.) maxintfloat(::Type{Float16}) = Float16(2048f0) -maxintfloat{T<:FloatingPoint}(x::T) = maxintfloat(T) +maxintfloat{T<:AbstractFloat}(x::T) = maxintfloat(T) maxintfloat() = maxintfloat(Float64) -isinteger(x::FloatingPoint) = (trunc(x)==x)&isfinite(x) +isinteger(x::AbstractFloat) = (trunc(x)==x)&isfinite(x) num2hex(x::Float16) = hex(reinterpret(UInt16,x), 4) num2hex(x::Float32) = hex(box(UInt32,unbox(Float32,x)),8) @@ -50,16 +50,16 @@ round(x::Real, ::RoundingMode{:ToZero}) = trunc(x) round(x::Real, ::RoundingMode{:Up}) = ceil(x) round(x::Real, ::RoundingMode{:Down}) = floor(x) # C-style round -function round(x::FloatingPoint, ::RoundingMode{:NearestTiesAway}) +function round(x::AbstractFloat, ::RoundingMode{:NearestTiesAway}) y = trunc(x) ifelse(x==y,y,trunc(2*x-y)) end # Java-style round -function round(x::FloatingPoint, ::RoundingMode{:NearestTiesUp}) +function round(x::AbstractFloat, ::RoundingMode{:NearestTiesUp}) y = floor(x) ifelse(x==y,y,copysign(floor(2*x-y),x)) end -round{T<:Integer}(::Type{T}, x::FloatingPoint, r::RoundingMode) = trunc(T,round(x,r)) +round{T<:Integer}(::Type{T}, x::AbstractFloat, r::RoundingMode) = trunc(T,round(x,r)) @vectorize_1arg Real trunc @vectorize_1arg Real floor @@ -166,13 +166,13 @@ for f in (:round, :ceil, :floor, :trunc) end # isapprox: Tolerant comparison of floating point numbers -function isapprox(x::FloatingPoint, y::FloatingPoint; rtol::Real=rtoldefault(x,y), atol::Real=atoldefault(x,y)) +function isapprox(x::AbstractFloat, y::AbstractFloat; rtol::Real=rtoldefault(x,y), atol::Real=atoldefault(x,y)) (isinf(x) || isinf(y)) ? x == y : abs(x-y) <= atol + rtol.*max(abs(x), abs(y)) end # promotion of non-floats -isapprox(x::Real, y::FloatingPoint; rtol::Real=rtoldefault(x, y), atol::Real=atoldefault(x, y)) = isapprox(promote(x, y)...; rtol=rtol, atol=atol) -isapprox(x::FloatingPoint, y::Real; rtol::Real=rtoldefault(x, y), atol::Real=atoldefault(x, y)) = isapprox(promote(x, y)...; rtol=rtol, atol=atol) +isapprox(x::Real, y::AbstractFloat; rtol::Real=rtoldefault(x, y), atol::Real=atoldefault(x, y)) = isapprox(promote(x, y)...; rtol=rtol, atol=atol) +isapprox(x::AbstractFloat, y::Real; rtol::Real=rtoldefault(x, y), atol::Real=atoldefault(x, y)) = isapprox(promote(x, y)...; rtol=rtol, atol=atol) # other real numbers isapprox(x::Real, y::Real; rtol::Real=0, atol::Real=0) = abs(x-y) <= atol @@ -185,13 +185,13 @@ isapprox(x::Real, z::Complex; rtol::Real=rtoldefault(x, abs(z)), atol::Real=atol isapprox(z::Complex, x::Real; rtol::Real=rtoldefault(x, abs(z)), atol::Real=atoldefault(x, abs(z))) = isapprox(complex(x), z; rtol=rtol, atol=atol) # default tolerance arguments -rtoldefault(x::FloatingPoint, y::FloatingPoint) = cbrt(max(eps(x), eps(y))) -atoldefault(x::FloatingPoint, y::FloatingPoint) = sqrt(max(eps(x), eps(y))) +rtoldefault(x::AbstractFloat, y::AbstractFloat) = cbrt(max(eps(x), eps(y))) +atoldefault(x::AbstractFloat, y::AbstractFloat) = sqrt(max(eps(x), eps(y))) # promotion of non-floats for fun in (:rtoldefault, :atoldefault) @eval begin - ($fun)(x::Real, y::FloatingPoint) = ($fun)(promote(x,y)...) - ($fun)(x::FloatingPoint, y::Real) = ($fun)(promote(x,y)...) + ($fun)(x::Real, y::AbstractFloat) = ($fun)(promote(x,y)...) + ($fun)(x::AbstractFloat, y::Real) = ($fun)(promote(x,y)...) end end diff --git a/base/grisu.jl b/base/grisu.jl index 3d46cba116909..5b9837b0e9dd8 100644 --- a/base/grisu.jl +++ b/base/grisu.jl @@ -22,7 +22,7 @@ include("grisu/bignum.jl") const BIGNUMS = [Bignums.Bignum(),Bignums.Bignum(),Bignums.Bignum(),Bignums.Bignum()] -function grisu(v::FloatingPoint,mode,requested_digits,buffer=DIGITS,bignums=BIGNUMS) +function grisu(v::AbstractFloat,mode,requested_digits,buffer=DIGITS,bignums=BIGNUMS) if signbit(v) neg = true v = -v @@ -52,14 +52,14 @@ function grisu(v::FloatingPoint,mode,requested_digits,buffer=DIGITS,bignums=BIGN return len-1, point, neg, buffer end -_show(io::IO, x::FloatingPoint, mode, n::Int, t) = +_show(io::IO, x::AbstractFloat, mode, n::Int, t) = _show(io, x, mode, n, t, "NaN", "Inf") _show(io::IO, x::Float32, mode, n::Int, t) = _show(io, x, mode, n, t, "NaN32", "Inf32") _show(io::IO, x::Float16, mode, n::Int, t) = _show(io, x, mode, n, t, "NaN16", "Inf16") -function _show(io::IO, x::FloatingPoint, mode, n::Int, typed, nanstr, infstr) +function _show(io::IO, x::AbstractFloat, mode, n::Int, typed, nanstr, infstr) isnan(x) && return write(io, typed ? nanstr : "NaN") if isinf(x) signbit(x) && write(io,'-') @@ -116,7 +116,7 @@ function _show(io::IO, x::FloatingPoint, mode, n::Int, typed, nanstr, infstr) nothing end -Base.show(io::IO, x::FloatingPoint) = _show(io, x, SHORTEST, 0, true) +Base.show(io::IO, x::AbstractFloat) = _show(io, x, SHORTEST, 0, true) Base.print(io::IO, x::Float32) = _show(io, x, SHORTEST, 0, false) Base.print(io::IO, x::Float16) = _show(io, x, SHORTEST, 0, false) @@ -134,7 +134,7 @@ Base.showcompact(io::IO, x::Float16) = _show(io, x, PRECISION, 5, false) # pt <= 0 ########e-### len+k+2 # 0 < pt ########e### len+k+1 -function _print_shortest(io::IO, x::FloatingPoint, dot::Bool, mode, n::Int) +function _print_shortest(io::IO, x::AbstractFloat, dot::Bool, mode, n::Int) isnan(x) && return write(io, "NaN") x < 0 && write(io,'-') isinf(x) && return write(io, "Inf") @@ -174,7 +174,7 @@ function _print_shortest(io::IO, x::FloatingPoint, dot::Bool, mode, n::Int) nothing end -print_shortest(io::IO, x::FloatingPoint, dot::Bool) = _print_shortest(io, x, dot, SHORTEST, 0) -print_shortest(io::IO, x::Union{FloatingPoint,Integer}) = print_shortest(io, float(x), false) +print_shortest(io::IO, x::AbstractFloat, dot::Bool) = _print_shortest(io, x, dot, SHORTEST, 0) +print_shortest(io::IO, x::Union{AbstractFloat,Integer}) = print_shortest(io, float(x), false) end # module diff --git a/base/grisu/float.jl b/base/grisu/float.jl index 7dd1ac7efe048..109b98b5bcea5 100644 --- a/base/grisu/float.jl +++ b/base/grisu/float.jl @@ -36,7 +36,7 @@ end Float() = Float(0,0,0) Float(x,y) = Float(x,y,Int32(0)) -Float(d::FloatingPoint) = Float(_significand(d), _exponent(d)) +Float(d::AbstractFloat) = Float(_significand(d), _exponent(d)) # Consts const Float10MSBits = 0xFFC0000000000000 # used normalize(Float) @@ -104,18 +104,18 @@ SignificandMask(::Type{Float16}) = 0x03ff HiddenBit(::Type{Float16}) = 0x0400 uint_t(d::Float16) = reinterpret(UInt16,d) -function _exponent{T<:FloatingPoint}(d::T) +function _exponent{T<:AbstractFloat}(d::T) isdenormal(d) && return DenormalExponent(T) biased_e::Int32 = Int32((uint_t(d) & ExponentMask(T)) >> PhysicalSignificandSize(T)) return Int32(biased_e - ExponentBias(T)) end -function _significand{T<:FloatingPoint}(d::T) +function _significand{T<:AbstractFloat}(d::T) s = uint_t(d) & SignificandMask(T) return !isdenormal(d) ? s + HiddenBit(T) : s end -isdenormal{T<:FloatingPoint}(d::T) = (uint_t(d) & ExponentMask(T)) == 0 +isdenormal{T<:AbstractFloat}(d::T) = (uint_t(d) & ExponentMask(T)) == 0 -function normalizedbound(f::FloatingPoint) +function normalizedbound(f::AbstractFloat) v = Float(_significand(f),_exponent(f)) m_plus = normalize(Float((v.s << 1) + 1, v.e - 1)) if lowerboundaryiscloser(f) @@ -125,7 +125,7 @@ function normalizedbound(f::FloatingPoint) end return Float(m_minus.s << (m_minus.e - m_plus.e), m_plus.e), m_plus end -function lowerboundaryiscloser{T<:FloatingPoint}(f::T) +function lowerboundaryiscloser{T<:AbstractFloat}(f::T) physical_significand_is_zero = (uint_t(f) & SignificandMask(T)) == 0 return physical_significand_is_zero && (_exponent(f) != DenormalExponent(T)) end diff --git a/base/irrationals.jl b/base/irrationals.jl index 0806d6b703b82..a3b189c19302d 100644 --- a/base/irrationals.jl +++ b/base/irrationals.jl @@ -10,7 +10,7 @@ promote_rule{s}(::Type{Irrational{s}}, ::Type{Float32}) = Float32 promote_rule{s,t}(::Type{Irrational{s}}, ::Type{Irrational{t}}) = Float64 promote_rule{s,T<:Number}(::Type{Irrational{s}}, ::Type{T}) = promote_type(Float64,T) -convert(::Type{FloatingPoint}, x::Irrational) = Float64(x) +convert(::Type{AbstractFloat}, x::Irrational) = Float64(x) convert(::Type{Float16}, x::Irrational) = Float16(Float32(x)) convert{T<:Real}(::Type{Complex{T}}, x::Irrational) = convert(Complex{T}, convert(T,x)) convert{T<:Integer}(::Type{Rational{T}}, x::Irrational) = convert(Rational{T}, Float64(x)) @@ -27,7 +27,7 @@ end ==(x::Irrational, y::Real) = false ==(x::Real, y::Irrational) = false -# Irrational vs FloatingPoint +# Irrational vs AbstractFloat <(x::Irrational, y::Float64) = Float64(x,RoundUp) <= y <(x::Float64, y::Irrational) = x <= Float64(y,RoundDown) <(x::Irrational, y::Float32) = Float32(x,RoundUp) <= y @@ -41,8 +41,8 @@ end x < big(y) end -<=(x::Irrational,y::FloatingPoint) = x < y -<=(x::FloatingPoint,y::Irrational) = x < y +<=(x::Irrational,y::AbstractFloat) = x < y +<=(x::AbstractFloat,y::Irrational) = x < y # Irrational vs Rational @generated function <{T}(x::Irrational, y::Rational{T}) diff --git a/base/linalg/givens.jl b/base/linalg/givens.jl index 3155a3b0a649d..cd0785560c491 100644 --- a/base/linalg/givens.jl +++ b/base/linalg/givens.jl @@ -44,7 +44,7 @@ realmin2{T}(::Type{T}) = (twopar = 2one(T); twopar^trunc(Integer,log(realmin(T)/ # Univ. of California Berkeley # Univ. of Colorado Denver # NAG Ltd. -function givensAlgorithm{T<:FloatingPoint}(f::T, g::T) +function givensAlgorithm{T<:AbstractFloat}(f::T, g::T) zeropar = zero(T) onepar = one(T) twopar = 2one(T) @@ -116,7 +116,7 @@ end # Univ. of California Berkeley # Univ. of Colorado Denver # NAG Ltd. -function givensAlgorithm{T<:FloatingPoint}(f::Complex{T}, g::Complex{T}) +function givensAlgorithm{T<:AbstractFloat}(f::Complex{T}, g::Complex{T}) twopar, onepar, zeropar = 2one(T), one(T), zero(T) czero = zero(Complex{T}) diff --git a/base/linalg/lapack.jl b/base/linalg/lapack.jl index d233a5b7c4c22..129361302b3e2 100644 --- a/base/linalg/lapack.jl +++ b/base/linalg/lapack.jl @@ -3150,7 +3150,7 @@ for (syev, syevr, sygvd, elty) in # * .. Array Arguments .. # INTEGER ISUPPZ( * ), IWORK( * ) # DOUBLE PRECISION A( LDA, * ), W( * ), WORK( * ), Z( LDZ, * ) - function syevr!(jobz::Char, range::Char, uplo::Char, A::StridedMatrix{$elty}, vl::FloatingPoint, vu::FloatingPoint, il::Integer, iu::Integer, abstol::FloatingPoint) + function syevr!(jobz::Char, range::Char, uplo::Char, A::StridedMatrix{$elty}, vl::AbstractFloat, vu::AbstractFloat, il::Integer, iu::Integer, abstol::AbstractFloat) chkstride1(A) n = chksquare(A) if range == 'I' && !(1 <= il <= iu <= n) @@ -3293,7 +3293,7 @@ for (syev, syevr, sygvd, elty, relty) in # INTEGER ISUPPZ( * ), IWORK( * ) # DOUBLE PRECISION RWORK( * ), W( * ) # COMPLEX*16 A( LDA, * ), WORK( * ), Z( LDZ, * ) - function syevr!(jobz::Char, range::Char, uplo::Char, A::StridedMatrix{$elty}, vl::FloatingPoint, vu::FloatingPoint, il::Integer, iu::Integer, abstol::FloatingPoint) + function syevr!(jobz::Char, range::Char, uplo::Char, A::StridedMatrix{$elty}, vl::AbstractFloat, vu::AbstractFloat, il::Integer, iu::Integer, abstol::AbstractFloat) chkstride1(A) n = chksquare(A) if range == 'I' && !(1 <= il <= iu <= n) diff --git a/base/linalg/lu.jl b/base/linalg/lu.jl index ac7d4d0d585a3..e579b4b6de068 100644 --- a/base/linalg/lu.jl +++ b/base/linalg/lu.jl @@ -67,7 +67,7 @@ function generic_lufact!{T,Pivot}(A::StridedMatrix{T}, ::Type{Val{Pivot}} = Val{ end # floating point types doesn't have to be promoted for LU, but should default to pivoting -lufact{T<:FloatingPoint}(A::Union{AbstractMatrix{T},AbstractMatrix{Complex{T}}}, pivot::Union{Type{Val{false}}, Type{Val{true}}} = Val{true}) = lufact!(copy(A), pivot) +lufact{T<:AbstractFloat}(A::Union{AbstractMatrix{T},AbstractMatrix{Complex{T}}}, pivot::Union{Type{Val{false}}, Type{Val{true}}} = Val{true}) = lufact!(copy(A), pivot) # for all other types we must promote to a type which is stable under division function lufact{T}(A::AbstractMatrix{T}, pivot::Union{Type{Val{false}}, Type{Val{true}}}) diff --git a/base/math.jl b/base/math.jl index 6a2d5b3d88dbe..6682f349035ff 100644 --- a/base/math.jl +++ b/base/math.jl @@ -111,10 +111,10 @@ for f in (:cbrt, :sinh, :cosh, :tanh, :atan, :asinh, :exp, :erf, :erfc, :exp2, : end # fallback definitions to prevent infinite loop from $f(x::Real) def above -cbrt(x::FloatingPoint) = x^(1//3) -exp2(x::FloatingPoint) = 2^x +cbrt(x::AbstractFloat) = x^(1//3) +exp2(x::AbstractFloat) = 2^x for f in (:sinh, :cosh, :tanh, :atan, :asinh, :exp, :erf, :erfc, :expm1) - @eval ($f)(x::FloatingPoint) = error("not implemented for ", typeof(x)) + @eval ($f)(x::AbstractFloat) = error("not implemented for ", typeof(x)) end # TODO: GNU libc has exp10 as an extension; should openlibm? @@ -140,7 +140,7 @@ sqrt(x::Real) = sqrt(float(x)) @vectorize_1arg Number sqrt hypot(x::Real, y::Real) = hypot(promote(float(x), float(y))...) -function hypot{T<:FloatingPoint}(x::T, y::T) +function hypot{T<:AbstractFloat}(x::T, y::T) x = abs(x) y = abs(y) if x < y @@ -160,7 +160,7 @@ function hypot{T<:FloatingPoint}(x::T, y::T) end atan2(y::Real, x::Real) = atan2(promote(float(y),float(x))...) -atan2{T<:FloatingPoint}(y::T, x::T) = Base.no_op_err("atan2", T) +atan2{T<:AbstractFloat}(y::T, x::T) = Base.no_op_err("atan2", T) for f in (:atan2, :hypot) @eval begin @@ -170,16 +170,16 @@ for f in (:atan2, :hypot) end end -max{T<:FloatingPoint}(x::T, y::T) = ifelse((y > x) | (signbit(y) < signbit(x)), +max{T<:AbstractFloat}(x::T, y::T) = ifelse((y > x) | (signbit(y) < signbit(x)), ifelse(isnan(y), x, y), ifelse(isnan(x), y, x)) @vectorize_2arg Real max -min{T<:FloatingPoint}(x::T, y::T) = ifelse((y < x) | (signbit(y) > signbit(x)), +min{T<:AbstractFloat}(x::T, y::T) = ifelse((y < x) | (signbit(y) > signbit(x)), ifelse(isnan(y), x, y), ifelse(isnan(x), y, x)) @vectorize_2arg Real min -minmax{T<:FloatingPoint}(x::T, y::T) = ifelse(isnan(x-y), ifelse(isnan(x), (y, y), (x, x)), +minmax{T<:AbstractFloat}(x::T, y::T) = ifelse(isnan(x-y), ifelse(isnan(x), (y, y), (x, x)), ifelse((y < x) | (signbit(y) > signbit(x)), (y, x), ifelse((y > x) | (signbit(y) < signbit(x)), (x, y), ifelse(x == x, (x, x), (y, y))))) @@ -188,7 +188,7 @@ ldexp(x::Float64,e::Integer) = ccall((:scalbn,libm), Float64, (Float64,Int32), ldexp(x::Float32,e::Integer) = ccall((:scalbnf,libm), Float32, (Float32,Int32), x, Int32(e)) # TODO: vectorize ldexp -function exponent{T<:FloatingPoint}(x::T) +function exponent{T<:AbstractFloat}(x::T) xu = reinterpret(Unsigned,x) xe = xu & exponent_mask(T) k = Int(xe >> significand_bits(T)) @@ -204,7 +204,7 @@ function exponent{T<:FloatingPoint}(x::T) end @vectorize_1arg Real exponent -function significand{T<:FloatingPoint}(x::T) +function significand{T<:AbstractFloat}(x::T) xu = reinterpret(Unsigned,x) xe = xu & exponent_mask(T) if xe == 0 # x is subnormal @@ -222,7 +222,7 @@ function significand{T<:FloatingPoint}(x::T) end @vectorize_1arg Real significand -function frexp{T<:FloatingPoint}(x::T) +function frexp{T<:AbstractFloat}(x::T) xu = reinterpret(Unsigned,x) xe = xu & exponent_mask(T) k = Int(xe >> significand_bits(T)) @@ -242,7 +242,7 @@ function frexp{T<:FloatingPoint}(x::T) reinterpret(T,xu), k end -function frexp{T<:FloatingPoint}(A::Array{T}) +function frexp{T<:AbstractFloat}(A::Array{T}) f = similar(A) e = Array(Int, size(A)) for i in eachindex(A) diff --git a/base/mpfr.jl b/base/mpfr.jl index c878733bbc7ad..071edc545c59c 100644 --- a/base/mpfr.jl +++ b/base/mpfr.jl @@ -40,7 +40,7 @@ const DEFAULT_PRECISION = [256] # Basic type and initialization definitions -type BigFloat <: FloatingPoint +type BigFloat <: AbstractFloat prec::Clong sign::Cint exp::Clong @@ -95,7 +95,7 @@ function tryparse(::Type{BigFloat}, s::AbstractString, base::Int=0) end convert(::Type{Rational}, x::BigFloat) = convert(Rational{BigInt}, x) -convert(::Type{FloatingPoint}, x::BigInt) = BigFloat(x) +convert(::Type{AbstractFloat}, x::BigInt) = BigFloat(x) ## BigFloat -> Integer function unsafe_cast(::Type{Int64}, x::BigFloat, ri::Cint) @@ -167,7 +167,7 @@ function convert{T<:Integer}(::Type{T},x::BigFloat) trunc(T,x) end -## BigFloat -> FloatingPoint +## BigFloat -> AbstractFloat convert(::Type{Float64}, x::BigFloat) = ccall((:mpfr_get_d,:libmpfr), Float64, (Ptr{BigFloat},Int32), &x, ROUNDING_MODE[end]) convert(::Type{Float32}, x::BigFloat) = @@ -184,10 +184,10 @@ call(::Type{Float16}, x::BigFloat, r::RoundingMode) = convert(Float16, call(Float32, x, r)) promote_rule{T<:Real}(::Type{BigFloat}, ::Type{T}) = BigFloat -promote_rule{T<:FloatingPoint}(::Type{BigInt},::Type{T}) = BigFloat -promote_rule{T<:FloatingPoint}(::Type{BigFloat},::Type{T}) = BigFloat +promote_rule{T<:AbstractFloat}(::Type{BigInt},::Type{T}) = BigFloat +promote_rule{T<:AbstractFloat}(::Type{BigFloat},::Type{T}) = BigFloat -function convert(::Type{Rational{BigInt}}, x::FloatingPoint) +function convert(::Type{Rational{BigInt}}, x::AbstractFloat) if isnan(x); return zero(BigInt)//zero(BigInt); end if isinf(x); return copysign(one(BigInt),x)//zero(BigInt); end if x == 0; return zero(BigInt) // one(BigInt); end diff --git a/base/operators.jl b/base/operators.jl index bd52411b6c5f4..a5ee8269804a6 100644 --- a/base/operators.jl +++ b/base/operators.jl @@ -11,13 +11,13 @@ super(T::DataType) = T.super ==(x,y) = x === y isequal(x, y) = x == y -isequal(x::FloatingPoint, y::FloatingPoint) = (isnan(x) & isnan(y)) | (signbit(x) == signbit(y)) & (x == y) -isequal(x::Real, y::FloatingPoint) = (isnan(x) & isnan(y)) | (signbit(x) == signbit(y)) & (x == y) -isequal(x::FloatingPoint, y::Real ) = (isnan(x) & isnan(y)) | (signbit(x) == signbit(y)) & (x == y) +isequal(x::AbstractFloat, y::AbstractFloat) = (isnan(x) & isnan(y)) | (signbit(x) == signbit(y)) & (x == y) +isequal(x::Real, y::AbstractFloat) = (isnan(x) & isnan(y)) | (signbit(x) == signbit(y)) & (x == y) +isequal(x::AbstractFloat, y::Real ) = (isnan(x) & isnan(y)) | (signbit(x) == signbit(y)) & (x == y) -isless(x::FloatingPoint, y::FloatingPoint) = (!isnan(x) & isnan(y)) | (signbit(x) & !signbit(y)) | (x < y) -isless(x::Real, y::FloatingPoint) = (!isnan(x) & isnan(y)) | (signbit(x) & !signbit(y)) | (x < y) -isless(x::FloatingPoint, y::Real ) = (!isnan(x) & isnan(y)) | (signbit(x) & !signbit(y)) | (x < y) +isless(x::AbstractFloat, y::AbstractFloat) = (!isnan(x) & isnan(y)) | (signbit(x) & !signbit(y)) | (x < y) +isless(x::Real, y::AbstractFloat) = (!isnan(x) & isnan(y)) | (signbit(x) & !signbit(y)) | (x < y) +isless(x::AbstractFloat, y::Real ) = (!isnan(x) & isnan(y)) | (signbit(x) & !signbit(y)) | (x < y) =={T}(::Type{T}, ::Type{T}) = true # encourage more specialization on types (see #11425) ==(T::Type, S::Type) = typeseq(T, S) @@ -327,7 +327,7 @@ for f in (:+, :-) range($f(r1.start,r2.start), $f(step(r1),step(r2)), r1l) end - function $f{T<:FloatingPoint}(r1::FloatRange{T}, r2::FloatRange{T}) + function $f{T<:AbstractFloat}(r1::FloatRange{T}, r2::FloatRange{T}) len = r1.len (len == r2.len || throw(DimensionMismatch("argument dimensions must match"))) @@ -346,7 +346,7 @@ for f in (:+, :-) end end - function $f{T<:FloatingPoint}(r1::LinSpace{T}, r2::LinSpace{T}) + function $f{T<:AbstractFloat}(r1::LinSpace{T}, r2::LinSpace{T}) len = r1.len (len == r2.len || throw(DimensionMismatch("argument dimensions must match"))) diff --git a/base/parse.jl b/base/parse.jl index c1f916d980441..111c5c6125410 100644 --- a/base/parse.jl +++ b/base/parse.jl @@ -159,7 +159,7 @@ tryparse{T<:ByteString}(::Type{Float32}, s::SubString{T}) = ccall(:jl_try_substr tryparse{T<:Union{Float32,Float64}}(::Type{T}, s::AbstractString) = tryparse(T, bytestring(s)) -function parse{T<:FloatingPoint}(::Type{T}, s::AbstractString) +function parse{T<:AbstractFloat}(::Type{T}, s::AbstractString) nf = tryparse(T, s) isnull(nf) ? throw(ArgumentError("invalid number format $(repr(s)) for $T")) : get(nf) end diff --git a/base/quadgk.jl b/base/quadgk.jl index 376bd4c08fba6..95696f125896a 100644 --- a/base/quadgk.jl +++ b/base/quadgk.jl @@ -152,13 +152,13 @@ end # Gauss-Kronrod quadrature of f from a to b to c... -function quadgk{T<:FloatingPoint}(f, a::T,b::T,c::T...; +function quadgk{T<:AbstractFloat}(f, a::T,b::T,c::T...; abstol=zero(T), reltol=sqrt(eps(T)), maxevals=10^7, order=7, norm=vecnorm) do_quadgk(f, [a, b, c...], order, T, abstol, reltol, maxevals, norm) end -function quadgk{T<:FloatingPoint}(f, a::Complex{T}, +function quadgk{T<:AbstractFloat}(f, a::Complex{T}, b::Complex{T},c::Complex{T}...; abstol=zero(T), reltol=sqrt(eps(T)), maxevals=10^7, order=7, norm=vecnorm) @@ -263,7 +263,7 @@ end # integrate functions on the interval (-1, 1). i.e. dot(f(x), w) # approximates the integral. Uses the method described in Trefethen & # Bau, Numerical Linear Algebra, to find the N-point Gaussian quadrature -function gauss{T<:FloatingPoint}(::Type{T}, N::Integer) +function gauss{T<:AbstractFloat}(::Type{T}, N::Integer) if N < 1 throw(ArgumentError("Gauss rules require positive order")) end @@ -279,7 +279,7 @@ end # Since the rule is symmetric only returns the n+1 points with x <= 0. # Also computes the embedded n-point Gauss quadrature weights gw (again # for x <= 0), corresponding to the points x[2:2:end]. Returns (x,w,wg). -function kronrod{T<:FloatingPoint}(::Type{T}, n::Integer) +function kronrod{T<:AbstractFloat}(::Type{T}, n::Integer) if n < 1 throw(ArgumentError("Kronrod rules require positive order")) end diff --git a/base/range.jl b/base/range.jl index bb758ae695fc6..52db2504d032b 100644 --- a/base/range.jl +++ b/base/range.jl @@ -22,7 +22,7 @@ end # to make StepRange constructor inlineable, so optimizer can see `step` value function steprange_last{T}(start::T, step, stop) - if isa(start,FloatingPoint) || isa(step,FloatingPoint) + if isa(start,AbstractFloat) || isa(step,AbstractFloat) throw(ArgumentError("StepRange should not be used with floating point")) end z = zero(step) @@ -102,13 +102,13 @@ range{T,S}(a::T, step::S, len::Integer) = StepRange{T,S}(a, step, convert(T, a+s ## floating point ranges -immutable FloatRange{T<:FloatingPoint} <: Range{T} +immutable FloatRange{T<:AbstractFloat} <: Range{T} start::T step::T len::T divisor::T end -FloatRange(a::FloatingPoint, s::FloatingPoint, l::Real, d::FloatingPoint) = +FloatRange(a::AbstractFloat, s::AbstractFloat, l::Real, d::AbstractFloat) = FloatRange{promote_type(typeof(a),typeof(s),typeof(d))}(a,s,l,d) # float rationalization helper @@ -129,7 +129,7 @@ function rat(x) return a, b end -function colon{T<:FloatingPoint}(start::T, step::T, stop::T) +function colon{T<:AbstractFloat}(start::T, step::T, stop::T) step == 0 && throw(ArgumentError("range step cannot be zero")) start == stop && return FloatRange{T}(start,step,1,1) (0 < step) != (start < stop) && return FloatRange{T}(start,step,0,1) @@ -159,27 +159,27 @@ function colon{T<:FloatingPoint}(start::T, step::T, stop::T) FloatRange{T}(start, step, floor(r)+1, one(step)) end -colon{T<:FloatingPoint}(a::T, b::T) = colon(a, one(a), b) +colon{T<:AbstractFloat}(a::T, b::T) = colon(a, one(a), b) -colon{T<:Real}(a::T, b::FloatingPoint, c::T) = colon(promote(a,b,c)...) -colon{T<:FloatingPoint}(a::T, b::FloatingPoint, c::T) = colon(promote(a,b,c)...) -colon{T<:FloatingPoint}(a::T, b::Real, c::T) = colon(promote(a,b,c)...) +colon{T<:Real}(a::T, b::AbstractFloat, c::T) = colon(promote(a,b,c)...) +colon{T<:AbstractFloat}(a::T, b::AbstractFloat, c::T) = colon(promote(a,b,c)...) +colon{T<:AbstractFloat}(a::T, b::Real, c::T) = colon(promote(a,b,c)...) -range(a::FloatingPoint, len::Integer) = FloatRange(a,one(a),len,one(a)) -range(a::FloatingPoint, st::FloatingPoint, len::Integer) = FloatRange(a,st,len,one(a)) -range(a::Real, st::FloatingPoint, len::Integer) = FloatRange(float(a), st, len, one(st)) -range(a::FloatingPoint, st::Real, len::Integer) = FloatRange(a, float(st), len, one(a)) +range(a::AbstractFloat, len::Integer) = FloatRange(a,one(a),len,one(a)) +range(a::AbstractFloat, st::AbstractFloat, len::Integer) = FloatRange(a,st,len,one(a)) +range(a::Real, st::AbstractFloat, len::Integer) = FloatRange(float(a), st, len, one(st)) +range(a::AbstractFloat, st::Real, len::Integer) = FloatRange(a, float(st), len, one(a)) ## linspace and logspace -immutable LinSpace{T<:FloatingPoint} <: Range{T} +immutable LinSpace{T<:AbstractFloat} <: Range{T} start::T stop::T len::T divisor::T end -function linspace{T<:FloatingPoint}(start::T, stop::T, len::T) +function linspace{T<:AbstractFloat}(start::T, stop::T, len::T) len == round(len) || throw(InexactError()) 0 <= len || error("linspace($start, $stop, $len): negative length") if len == 0 @@ -226,13 +226,13 @@ function linspace{T<:FloatingPoint}(start::T, stop::T, len::T) end return LinSpace(start, stop, len, n) end -function linspace{T<:FloatingPoint}(start::T, stop::T, len::Real) +function linspace{T<:AbstractFloat}(start::T, stop::T, len::Real) T_len = convert(T, len) T_len == len || throw(InexactError()) linspace(start, stop, T_len) end linspace(start::Real, stop::Real, len::Real=50) = - linspace(promote(FloatingPoint(start), FloatingPoint(stop))..., len) + linspace(promote(AbstractFloat(start), AbstractFloat(stop))..., len) function show(io::IO, r::LinSpace) print(io, "linspace(") diff --git a/base/rational.jl b/base/rational.jl index 2032654159c77..dc32a6cdb5eb3 100644 --- a/base/rational.jl +++ b/base/rational.jl @@ -66,13 +66,13 @@ convert(::Type{Rational}, x::Integer) = convert(Rational{typeof(x)},x) convert(::Type{Bool}, x::Rational) = x==0 ? false : x==1 ? true : throw(InexactError()) # to resolve ambiguity convert{T<:Integer}(::Type{T}, x::Rational) = (isinteger(x) ? convert(T, x.num) : throw(InexactError())) -convert(::Type{FloatingPoint}, x::Rational) = float(x.num)/float(x.den) -function convert{T<:FloatingPoint,S}(::Type{T}, x::Rational{S}) +convert(::Type{AbstractFloat}, x::Rational) = float(x.num)/float(x.den) +function convert{T<:AbstractFloat,S}(::Type{T}, x::Rational{S}) P = promote_type(T,S) convert(T, convert(P,x.num)/convert(P,x.den)) end -function convert{T<:Integer}(::Type{Rational{T}}, x::FloatingPoint) +function convert{T<:Integer}(::Type{Rational{T}}, x::AbstractFloat) r = rationalize(T, x, tol=0) x == convert(typeof(x), r) || throw(InexactError()) r @@ -85,11 +85,11 @@ big{T<:Integer,N}(x::AbstractArray{Complex{Rational{T}},N}) = convert(AbstractAr promote_rule{T<:Integer,S<:Integer}(::Type{Rational{T}}, ::Type{S}) = Rational{promote_type(T,S)} promote_rule{T<:Integer,S<:Integer}(::Type{Rational{T}}, ::Type{Rational{S}}) = Rational{promote_type(T,S)} -promote_rule{T<:Integer,S<:FloatingPoint}(::Type{Rational{T}}, ::Type{S}) = promote_type(T,S) +promote_rule{T<:Integer,S<:AbstractFloat}(::Type{Rational{T}}, ::Type{S}) = promote_type(T,S) widen{T}(::Type{Rational{T}}) = Rational{widen(T)} -function rationalize{T<:Integer}(::Type{T}, x::FloatingPoint; tol::Real=eps(x)) +function rationalize{T<:Integer}(::Type{T}, x::AbstractFloat; tol::Real=eps(x)) tol < 0 && throw(ArgumentError("negative tolerance")) isnan(x) && return zero(T)//zero(T) isinf(x) && return (x < 0 ? -one(T) : one(T))//zero(T) @@ -136,7 +136,7 @@ function rationalize{T<:Integer}(::Type{T}, x::FloatingPoint; tol::Real=eps(x)) return p // q end end -rationalize(x::FloatingPoint; kvs...) = rationalize(Int, x; kvs...) +rationalize(x::AbstractFloat; kvs...) = rationalize(Int, x; kvs...) num(x::Integer) = x den(x::Integer) = one(x) @@ -197,7 +197,7 @@ fma(x::Rational, y::Rational, z::Rational) = x*y+z <=(x::Rational, y::Integer ) = x.num <= widemul(x.den,y) <=(x::Integer , y::Rational) = widemul(x,y.den) <= y.num -function ==(x::FloatingPoint, q::Rational) +function ==(x::AbstractFloat, q::Rational) if isfinite(x) (count_ones(q.den) == 1) & (x*q.den == q.num) else @@ -205,10 +205,10 @@ function ==(x::FloatingPoint, q::Rational) end end -==(q::Rational, x::FloatingPoint) = x == q +==(q::Rational, x::AbstractFloat) = x == q for rel in (:<,:<=,:cmp) - for (Tx,Ty) in ((Rational,FloatingPoint), (FloatingPoint,Rational)) + for (Tx,Ty) in ((Rational,AbstractFloat), (AbstractFloat,Rational)) @eval function ($rel)(x::$Tx, y::$Ty) if isnan(x) || isnan(y) $(rel == :cmp ? :(throw(DomainError())) : :(return false)) @@ -306,8 +306,8 @@ function ^(x::Rational, n::Integer) end ^(x::Number, y::Rational) = x^(y.num/y.den) -^{T<:FloatingPoint}(x::T, y::Rational) = x^(convert(T,y.num)/y.den) -^{T<:FloatingPoint}(x::Complex{T}, y::Rational) = x^(convert(T,y.num)/y.den) +^{T<:AbstractFloat}(x::T, y::Rational) = x^(convert(T,y.num)/y.den) +^{T<:AbstractFloat}(x::Complex{T}, y::Rational) = x^(convert(T,y.num)/y.den) ^{T<:Rational}(z::Complex{T}, n::Bool) = n ? z : one(z) # to resolve ambiguity function ^{T<:Rational}(z::Complex{T}, n::Integer) diff --git a/base/reduce.jl b/base/reduce.jl index 7ba0955c325d6..0d0a282f88cb1 100644 --- a/base/reduce.jl +++ b/base/reduce.jl @@ -247,7 +247,7 @@ sumabs2(a) = mapreduce(Abs2Fun(), AddFun(), a) # Kahan (compensated) summation: O(1) error growth, at the expense # of a considerable increase in computational expense. -function sum_kbn{T<:FloatingPoint}(A::AbstractArray{T}) +function sum_kbn{T<:AbstractFloat}(A::AbstractArray{T}) n = length(A) c = r_promote(AddFun(), zero(T)::T) if n == 0 diff --git a/base/rounding.jl b/base/rounding.jl index a6e40daf4af1b..96490407452c2 100644 --- a/base/rounding.jl +++ b/base/rounding.jl @@ -66,18 +66,18 @@ end # Assumes conversion is performed by rounding to nearest value. # To avoid ambiguous dispatch with methods in mpfr.jl: -call{T<:FloatingPoint}(::Type{T},x::Real,r::RoundingMode) = _convert_rounding(T,x,r) +call{T<:AbstractFloat}(::Type{T},x::Real,r::RoundingMode) = _convert_rounding(T,x,r) -_convert_rounding{T<:FloatingPoint}(::Type{T},x::Real,r::RoundingMode{:Nearest}) = convert(T,x) -function _convert_rounding{T<:FloatingPoint}(::Type{T},x::Real,r::RoundingMode{:Down}) +_convert_rounding{T<:AbstractFloat}(::Type{T},x::Real,r::RoundingMode{:Nearest}) = convert(T,x) +function _convert_rounding{T<:AbstractFloat}(::Type{T},x::Real,r::RoundingMode{:Down}) y = convert(T,x) y > x ? prevfloat(y) : y end -function _convert_rounding{T<:FloatingPoint}(::Type{T},x::Real,r::RoundingMode{:Up}) +function _convert_rounding{T<:AbstractFloat}(::Type{T},x::Real,r::RoundingMode{:Up}) y = convert(T,x) y < x ? nextfloat(y) : y end -function _convert_rounding{T<:FloatingPoint}(::Type{T},x::Real,r::RoundingMode{:ToZero}) +function _convert_rounding{T<:AbstractFloat}(::Type{T},x::Real,r::RoundingMode{:ToZero}) y = convert(T,x) if x > 0.0 y > x ? prevfloat(y) : y diff --git a/base/sparse/sparsematrix.jl b/base/sparse/sparsematrix.jl index a95f5f2bd3e39..80e30d9ae7f52 100644 --- a/base/sparse/sparsematrix.jl +++ b/base/sparse/sparsematrix.jl @@ -397,7 +397,7 @@ end import Base.Random.GLOBAL_RNG -function sprand_IJ(r::AbstractRNG, m::Integer, n::Integer, density::FloatingPoint) +function sprand_IJ(r::AbstractRNG, m::Integer, n::Integer, density::AbstractFloat) ((m < 0) || (n < 0)) && throw(ArgumentError("invalid Array dimensions")) 0 <= density <= 1 || throw(ArgumentError("$density not in [0,1]")) N = n*m @@ -434,7 +434,7 @@ function sprand_IJ(r::AbstractRNG, m::Integer, n::Integer, density::FloatingPoin I, J end -function sprand{T}(r::AbstractRNG, m::Integer, n::Integer, density::FloatingPoint, +function sprand{T}(r::AbstractRNG, m::Integer, n::Integer, density::AbstractFloat, rfn::Function, ::Type{T}=eltype(rfn(r,1))) N = m*n N == 0 && return spzeros(T,m,n) @@ -444,7 +444,7 @@ function sprand{T}(r::AbstractRNG, m::Integer, n::Integer, density::FloatingPoin sparse_IJ_sorted!(I, J, rfn(r,length(I)), m, n, AddFun()) # it will never need to combine end -function sprand{T}(m::Integer, n::Integer, density::FloatingPoint, +function sprand{T}(m::Integer, n::Integer, density::AbstractFloat, rfn::Function, ::Type{T}=eltype(rfn(1))) N = m*n N == 0 && return spzeros(T,m,n) @@ -454,14 +454,14 @@ function sprand{T}(m::Integer, n::Integer, density::FloatingPoint, sparse_IJ_sorted!(I, J, rfn(length(I)), m, n, AddFun()) # it will never need to combine end -sprand(r::AbstractRNG, m::Integer, n::Integer, density::FloatingPoint) = sprand(r,m,n,density,rand,Float64) -sprand(m::Integer, n::Integer, density::FloatingPoint) = sprand(GLOBAL_RNG,m,n,density) -sprandn(r::AbstractRNG, m::Integer, n::Integer, density::FloatingPoint) = sprand(r,m,n,density,randn,Float64) -sprandn( m::Integer, n::Integer, density::FloatingPoint) = sprandn(GLOBAL_RNG,m,n,density) +sprand(r::AbstractRNG, m::Integer, n::Integer, density::AbstractFloat) = sprand(r,m,n,density,rand,Float64) +sprand(m::Integer, n::Integer, density::AbstractFloat) = sprand(GLOBAL_RNG,m,n,density) +sprandn(r::AbstractRNG, m::Integer, n::Integer, density::AbstractFloat) = sprand(r,m,n,density,randn,Float64) +sprandn( m::Integer, n::Integer, density::AbstractFloat) = sprandn(GLOBAL_RNG,m,n,density) truebools(r::AbstractRNG, n::Integer) = ones(Bool, n) -sprandbool(r::AbstractRNG, m::Integer, n::Integer, density::FloatingPoint) = sprand(r,m,n,density,truebools,Bool) -sprandbool(m::Integer, n::Integer, density::FloatingPoint) = sprandbool(GLOBAL_RNG,m,n,density) +sprandbool(r::AbstractRNG, m::Integer, n::Integer, density::AbstractFloat) = sprand(r,m,n,density,truebools,Bool) +sprandbool(m::Integer, n::Integer, density::AbstractFloat) = sprandbool(GLOBAL_RNG,m,n,density) spones{T}(S::SparseMatrixCSC{T}) = SparseMatrixCSC(S.m, S.n, copy(S.colptr), copy(S.rowval), ones(T, S.colptr[end]-1)) diff --git a/base/sparse/spqr.jl b/base/sparse/spqr.jl index a67605d28d0b2..bf9fe5b5365e6 100644 --- a/base/sparse/spqr.jl +++ b/base/sparse/spqr.jl @@ -145,4 +145,4 @@ function (\){T}(F::Factorization{T}, B::StridedVecOrMat{T}) convert(typeof(B), solve(RETX_EQUALS_B, F, QtB)) end -end # module \ No newline at end of file +end # module diff --git a/base/special/bessel.jl b/base/special/bessel.jl index 32d24c05fcb37..f4248b70f93ae 100644 --- a/base/special/bessel.jl +++ b/base/special/bessel.jl @@ -85,7 +85,7 @@ airybi(z) = airy(2,z) airybiprime(z) = airy(3,z) @vectorize_1arg Number airybiprime -airy(k::Number, x::FloatingPoint) = oftype(x, real(airy(k, complex(x)))) +airy(k::Number, x::AbstractFloat) = oftype(x, real(airy(k, complex(x)))) airy(k::Number, x::Real) = airy(k, float(x)) airy(k::Number, z::Complex64) = Complex64(airy(k, Complex128(z))) airy(k::Number, z::Complex) = airy(convert(Int,k), Complex128(z)) @@ -105,7 +105,7 @@ end airyx(z) = airyx(0,z) @vectorize_1arg Number airyx -airyx(k::Number, x::FloatingPoint) = oftype(x, real(airyx(k, complex(x)))) +airyx(k::Number, x::AbstractFloat) = oftype(x, real(airyx(k, complex(x)))) airyx(k::Number, x::Real) = airyx(k, float(x)) airyx(k::Number, z::Complex64) = Complex64(airyx(k, Complex128(z))) airyx(k::Number, z::Complex) = airyx(convert(Int,k), Complex128(z)) @@ -227,7 +227,7 @@ function besselj(nu::Float64, z::Complex128) end end -besselj(nu::Integer, x::FloatingPoint) = typemin(Int32) <= nu <= typemax(Int32) ? +besselj(nu::Integer, x::AbstractFloat) = typemin(Int32) <= nu <= typemax(Int32) ? oftype(x, ccall((:jn, libm), Float64, (Cint, Float64), nu, x)) : besselj(Float64(nu), x) @@ -285,21 +285,21 @@ hankelh1x(nu, z) = besselhx(nu, 1, z) hankelh2x(nu, z) = besselhx(nu, 2, z) @vectorize_2arg Number hankelh2x -function besseli(nu::Real, x::FloatingPoint) +function besseli(nu::Real, x::AbstractFloat) if x < 0 && !isinteger(nu) throw(DomainError()) end oftype(x, real(besseli(Float64(nu), Complex128(x)))) end -function besselix(nu::Real, x::FloatingPoint) +function besselix(nu::Real, x::AbstractFloat) if x < 0 && !isinteger(nu) throw(DomainError()) end oftype(x, real(besselix(Float64(nu), Complex128(x)))) end -function besselj(nu::FloatingPoint, x::FloatingPoint) +function besselj(nu::AbstractFloat, x::AbstractFloat) if isinteger(nu) if typemin(Int32) <= nu <= typemax(Int32) return besselj(Int(nu), x) @@ -310,14 +310,14 @@ function besselj(nu::FloatingPoint, x::FloatingPoint) oftype(x, real(besselj(Float64(nu), Complex128(x)))) end -function besseljx(nu::Real, x::FloatingPoint) +function besseljx(nu::Real, x::AbstractFloat) if x < 0 && !isinteger(nu) throw(DomainError()) end oftype(x, real(besseljx(Float64(nu), Complex128(x)))) end -function besselk(nu::Real, x::FloatingPoint) +function besselk(nu::Real, x::AbstractFloat) if x < 0 throw(DomainError()) end @@ -327,7 +327,7 @@ function besselk(nu::Real, x::FloatingPoint) oftype(x, real(besselk(Float64(nu), Complex128(x)))) end -function besselkx(nu::Real, x::FloatingPoint) +function besselkx(nu::Real, x::AbstractFloat) if x < 0 throw(DomainError()) end @@ -337,7 +337,7 @@ function besselkx(nu::Real, x::FloatingPoint) oftype(x, real(besselkx(Float64(nu), Complex128(x)))) end -function bessely(nu::Real, x::FloatingPoint) +function bessely(nu::Real, x::AbstractFloat) if x < 0 throw(DomainError()) end @@ -346,7 +346,7 @@ function bessely(nu::Real, x::FloatingPoint) end oftype(x, real(bessely(Float64(nu), Complex128(x)))) end -function bessely(nu::Integer, x::FloatingPoint) +function bessely(nu::Integer, x::AbstractFloat) if x < 0 throw(DomainError()) end @@ -359,7 +359,7 @@ function bessely(nu::Integer, x::Float32) return ccall((:ynf, libm), Float32, (Cint, Float32), nu, x) end -function besselyx(nu::Real, x::FloatingPoint) +function besselyx(nu::Real, x::AbstractFloat) if x < 0 throw(DomainError()) end diff --git a/base/special/trig.jl b/base/special/trig.jl index 02b70c3986270..f3da9d068fc0e 100644 --- a/base/special/trig.jl +++ b/base/special/trig.jl @@ -99,7 +99,7 @@ mulpi_ext(x::Rational) = mulpi_ext(float(x)) mulpi_ext(x::Real) = pi*x # Fallback -function sinpi{T<:FloatingPoint}(x::T) +function sinpi{T<:AbstractFloat}(x::T) if !isfinite(x) isnan(x) && return x throw(DomainError()) @@ -157,7 +157,7 @@ function sinpi{T<:Real}(x::T) end end -function cospi{T<:FloatingPoint}(x::T) +function cospi{T<:AbstractFloat}(x::T) if !isfinite(x) isnan(x) && return x throw(DomainError()) diff --git a/base/statistics.jl b/base/statistics.jl index 8831b798e4835..d7389b3c1a5a6 100644 --- a/base/statistics.jl +++ b/base/statistics.jl @@ -449,7 +449,7 @@ end # Specialized functions for real types allow for improved performance middle(x::Union{Bool,Int8,Int16,Int32,Int64,Int128,UInt8,UInt16,UInt32,UInt64,UInt128}) = Float64(x) -middle(x::FloatingPoint) = x +middle(x::AbstractFloat) = x middle(x::Float16) = Float32(x) middle(x::Real) = (x + zero(x)) / 1 middle(x::Real, y::Real) = x/2 + y/2 @@ -458,7 +458,7 @@ middle(a::AbstractArray) = ((v1, v2) = extrema(a); middle(v1, v2)) function median!{T}(v::AbstractVector{T}) isempty(v) && throw(ArgumentError("median of an empty array is undefined, $(repr(v))")) - if T<:FloatingPoint + if T<:AbstractFloat @inbounds for x in v isnan(x) && return x end @@ -518,7 +518,7 @@ end ## nice-valued ranges for histograms -function histrange{T<:FloatingPoint,N}(v::AbstractArray{T,N}, n::Integer) +function histrange{T<:AbstractFloat,N}(v::AbstractArray{T,N}, n::Integer) nv = length(v) if nv == 0 && n < 0 throw(ArgumentError("number of bins must be ≥ 0 for an empty array, got $n")) diff --git a/base/sysimg.jl b/base/sysimg.jl index af2c760bc9107..ccb0da02f56dd 100644 --- a/base/sysimg.jl +++ b/base/sysimg.jl @@ -177,7 +177,7 @@ importall .GMP include("mpfr.jl") importall .MPFR big(n::Integer) = convert(BigInt,n) -big(x::FloatingPoint) = convert(BigFloat,x) +big(x::AbstractFloat) = convert(BigFloat,x) big(q::Rational) = big(num(q))//big(den(q)) include("combinatorics.jl") diff --git a/contrib/julia-mode.el b/contrib/julia-mode.el index 0c30e2545eb19..8a779d7deb7b4 100644 --- a/contrib/julia-mode.el +++ b/contrib/julia-mode.el @@ -209,7 +209,7 @@ This function provides equivalent functionality, but makes no efforts to optimis '("Number" "Real" "BigInt" "Integer" "UInt" "UInt8" "UInt16" "UInt32" "UInt64" "UInt128" "Int" "Int8" "Int16" "Int32" "Int64" "Int128" - "BigFloat" "FloatingPoint" "Float16" "Float32" "Float64" + "BigFloat" "AbstractFloat" "Float16" "Float32" "Float64" "Complex128" "Complex64" "Bool" "Cuchar" "Cshort" "Cushort" "Cint" "Cuint" "Clonglong" "Culonglong" "Cintmax_t" "Cuintmax_t" diff --git a/contrib/julia.hrc b/contrib/julia.hrc index 6849b19212088..29372ce137edf 100644 --- a/contrib/julia.hrc +++ b/contrib/julia.hrc @@ -118,7 +118,7 @@ - + diff --git a/contrib/julia.xml b/contrib/julia.xml index aab0c7ce48015..587841cdc657d 100644 --- a/contrib/julia.xml +++ b/contrib/julia.xml @@ -115,7 +115,7 @@ FileMonitor FileOffset Filter - FloatingPoint + AbstractFloat Float16 Float32 Float64 diff --git a/contrib/windows/julia.rc b/contrib/windows/julia.rc index 50aada97f532b..03ef0f499881b 100644 --- a/contrib/windows/julia.rc +++ b/contrib/windows/julia.rc @@ -30,4 +30,4 @@ BEGIN VALUE "Translation", 0x409, 1200 END END -2 ICON "julia.ico" \ No newline at end of file +2 ICON "julia.ico" diff --git a/doc/devdocs/reflection.rst b/doc/devdocs/reflection.rst index 1a827905834cc..40f49c65dd48a 100644 --- a/doc/devdocs/reflection.rst +++ b/doc/devdocs/reflection.rst @@ -52,12 +52,12 @@ one of these fields is the ``types`` field observed in the example above. .. rubric:: Subtypes The *direct* subtypes of any :obj:`DataType` may be listed using -:func:`subtypes`. For example, the abstract :obj:`DataType` :obj:`FloatingPoint` +:func:`subtypes`. For example, the abstract :obj:`DataType` :obj:`AbstractFloat` has four (concrete) subtypes: .. doctest:: - julia> subtypes(FloatingPoint) + julia> subtypes(AbstractFloat) 4-element Array{Any,1}: Base.MPFR.BigFloat Float16 diff --git a/doc/devdocs/types.rst b/doc/devdocs/types.rst index 820ae1c72ab8d..24d44b5ecca0f 100644 --- a/doc/devdocs/types.rst +++ b/doc/devdocs/types.rst @@ -597,9 +597,9 @@ comparing type parameters and otherwise is 0. The rules for these are somewhat different. ``subtype`` is sensitive to the number arguments, but ``type_morespecific`` may not be. In -particular, ``Tuple{Int,FloatingPoint}`` is more specific than +particular, ``Tuple{Int,AbstractFloat}`` is more specific than ``Tuple{Integer}``, even though it is not a subtype. (Of -``Tuple{Int,FloatingPoint}`` and ``Tuple{Integer,Float64}``, neither +``Tuple{Int,AbstractFloat}`` and ``Tuple{Integer,Float64}``, neither is more specific than the other.) Likewise, ``Tuple{Int,Vararg{Int}}`` is not a subtype of ``Tuple{Integer}``, but it is considered more specific. However, ``morespecific`` does get a bonus for length: diff --git a/doc/helpdb.jl b/doc/helpdb.jl index 6fbcb47df5957..74ef81f9010c9 100644 --- a/doc/helpdb.jl +++ b/doc/helpdb.jl @@ -1645,7 +1645,7 @@ Any[ ERROR: InexactError() in convert at int.jl:196 - If \"T\" is a \"FloatingPoint\" or \"Rational\" type, then it will + If \"T\" is a \"AbstractFloat\" or \"Rational\" type, then it will return the closest value to \"x\" representable by \"T\". julia> x = 1/3 @@ -9117,12 +9117,12 @@ Mmap.mmap(type::Type{Array{T, N}}, dims) Inexact equality comparison - behaves slightly different depending on types of input args: - * For \"FloatingPoint\" numbers, \"isapprox\" returns \"true\" if + * For \"AbstractFloat\" numbers, \"isapprox\" returns \"true\" if \"abs(x-y) <= atol + rtol*max(abs(x), abs(y))\". * For \"Integer\" and \"Rational\" numbers, \"isapprox\" returns \"true\" if \"abs(x-y) <= atol\". The *rtol* argument is ignored. - If one of \"x\" and \"y\" is \"FloatingPoint\", the other is + If one of \"x\" and \"y\" is \"AbstractFloat\", the other is promoted, and the method above is called instead. * For \"Complex\" numbers, the distance in the complex plane is @@ -11044,8 +11044,8 @@ Mmap.mmap(type::Type{Array{T, N}}, dims) ("Base","float","float(x) - Convert a number, array, or string to a \"FloatingPoint\" data - type. For numeric data, the smallest suitable \"FloatingPoint\" + Convert a number, array, or string to a \"AbstractFloat\" data + type. For numeric data, the smallest suitable \"AbstractFloat\" type is used. Converts strings to \"Float64\". "), @@ -11246,7 +11246,7 @@ golden "), -("Base","prevfloat","prevfloat(f) -> FloatingPoint +("Base","prevfloat","prevfloat(f) -> AbstractFloat Get the previous floating point number in lexicographic order @@ -11493,7 +11493,7 @@ golden "), -("Base","precision","precision(num::FloatingPoint) +("Base","precision","precision(num::AbstractFloat) Get the precision of a floating point number, as defined by the effective number of bits in the mantissa. diff --git a/doc/manual/conversion-and-promotion.rst b/doc/manual/conversion-and-promotion.rst index b527dee448d7a..89412562dc5d1 100644 --- a/doc/manual/conversion-and-promotion.rst +++ b/doc/manual/conversion-and-promotion.rst @@ -84,7 +84,7 @@ action: julia> typeof(ans) UInt8 - julia> convert(FloatingPoint, x) + julia> convert(AbstractFloat, x) 12.0 julia> typeof(ans) @@ -96,14 +96,14 @@ requested conversion: .. doctest:: - julia> convert(FloatingPoint, "foo") - ERROR: MethodError: `convert` has no method matching convert(::Type{FloatingPoint}, ::ASCIIString) - This may have arisen from a call to the constructor FloatingPoint(...), + julia> convert(AbstractFloat, "foo") + ERROR: MethodError: `convert` has no method matching convert(::Type{AbstractFloat}, ::ASCIIString) + This may have arisen from a call to the constructor AbstractFloat(...), since type constructors fall back to convert methods. Closest candidates are: call{T}(::Type{T}, ::Any) - convert(::Type{FloatingPoint}, !Matched::Bool) - convert(::Type{FloatingPoint}, !Matched::Int8) + convert(::Type{AbstractFloat}, !Matched::Bool) + convert(::Type{AbstractFloat}, !Matched::Int8) ... Some languages consider parsing strings as numbers or formatting @@ -175,7 +175,7 @@ right after the declaration of the type and its constructors:: convert{T<:Integer}(::Type{Rational{T}}, x::Rational) = Rational(convert(T,x.num),convert(T,x.den)) convert{T<:Integer}(::Type{Rational{T}}, x::Integer) = Rational(convert(T,x), convert(T,1)) - function convert{T<:Integer}(::Type{Rational{T}}, x::FloatingPoint, tol::Real) + function convert{T<:Integer}(::Type{Rational{T}}, x::AbstractFloat, tol::Real) if isnan(x); return zero(T)//zero(T); end if isinf(x); return sign(x)//zero(T); end y = x @@ -190,9 +190,9 @@ right after the declaration of the type and its constructors:: y = 1/y end end - convert{T<:Integer}(rt::Type{Rational{T}}, x::FloatingPoint) = convert(rt,x,eps(x)) + convert{T<:Integer}(rt::Type{Rational{T}}, x::AbstractFloat) = convert(rt,x,eps(x)) - convert{T<:FloatingPoint}(::Type{T}, x::Rational) = convert(T,x.num)/convert(T,x.den) + convert{T<:AbstractFloat}(::Type{T}, x::Rational) = convert(T,x.num)/convert(T,x.den) convert{T<:Integer}(::Type{T}, x::Rational) = div(convert(T,x.num),convert(T,x.den)) The initial four convert methods provide conversions to rational types. @@ -372,7 +372,7 @@ mechanism with the following promotion rules:: promote_rule{T<:Integer}(::Type{Rational{T}}, ::Type{T}) = Rational{T} promote_rule{T<:Integer,S<:Integer}(::Type{Rational{T}}, ::Type{S}) = Rational{promote_type(T,S)} promote_rule{T<:Integer,S<:Integer}(::Type{Rational{T}}, ::Type{Rational{S}}) = Rational{promote_type(T,S)} - promote_rule{T<:Integer,S<:FloatingPoint}(::Type{Rational{T}}, ::Type{S}) = promote_type(T,S) + promote_rule{T<:Integer,S<:AbstractFloat}(::Type{Rational{T}}, ::Type{S}) = promote_type(T,S) The first rule asserts that promotion of a rational number with its own numerator/denominator type, simply promotes to itself. The second rule diff --git a/doc/manual/faq.rst b/doc/manual/faq.rst index 8d39cb04015ae..f98a04ae76d29 100644 --- a/doc/manual/faq.rst +++ b/doc/manual/faq.rst @@ -495,7 +495,7 @@ case the natural solution is to use parameters. For example: .. doctest:: - julia> type MyType{T<:FloatingPoint} + julia> type MyType{T<:AbstractFloat} a::T end @@ -504,7 +504,7 @@ This is a better choice than .. doctest:: julia> type MyStillAmbiguousType - a::FloatingPoint + a::AbstractFloat end because the first version specifies the type of ``a`` from the type of @@ -561,8 +561,8 @@ an abstract type: .. doctest:: - julia> m = MyType{FloatingPoint}(3.2) - MyType{FloatingPoint}(3.2) + julia> m = MyType{AbstractFloat}(3.2) + MyType{AbstractFloat}(3.2) julia> typeof(m.a) Float64 @@ -586,7 +586,7 @@ using :: code_llvm(func,(MyType{Float64},)) - code_llvm(func,(MyType{FloatingPoint},)) + code_llvm(func,(MyType{AbstractFloat},)) code_llvm(func,(MyType,)) For reasons of length the results are not shown here, but you may wish @@ -656,7 +656,7 @@ separate function:: end foo(x::Integer) = x - foo(x::FloatingPoint) = round(x) + foo(x::AbstractFloat) = round(x) This keeps things simple, while allowing the compiler to generate optimized code in all cases. @@ -665,7 +665,7 @@ However, there are cases where you may need to declare different versions of the outer function for different element types of ``a``. You could do it like this:: - function myfun{T<:FloatingPoint}(c::MySimpleContainer{Vector{T}}) + function myfun{T<:AbstractFloat}(c::MySimpleContainer{Vector{T}}) ... end function myfun{T<:Integer}(c::MySimpleContainer{Vector{T}}) @@ -699,7 +699,7 @@ With this approach, one can write functions such as:: # the previous could have been written more succinctly as # function myfunc{T<:Integer}(c::MyContainer{T}) - function myfunc{T<:FloatingPoint}(c::MyContainer{T}) + function myfunc{T<:AbstractFloat}(c::MyContainer{T}) return c.a[1]+2 end diff --git a/doc/manual/methods.rst b/doc/manual/methods.rst index adf7cb9d5c5c2..7935b1d71d746 100644 --- a/doc/manual/methods.rst +++ b/doc/manual/methods.rst @@ -229,7 +229,7 @@ Julia language. Core operations typically have dozens of methods:: # 139 methods for generic function "+": +(x::Bool) at bool.jl:33 +(x::Bool,y::Bool) at bool.jl:36 - +(y::FloatingPoint,x::Bool) at bool.jl:46 + +(y::AbstractFloat,x::Bool) at bool.jl:46 +(x::Int64,y::Int64) at int.jl:14 +(x::Int8,y::Int8) at int.jl:14 +(x::UInt8,y::UInt8) at int.jl:14 @@ -269,17 +269,17 @@ Julia language. Core operations typically have dozens of methods:: +(a::Base.MPFR.BigFloat,b::Base.MPFR.BigFloat,c::Base.MPFR.BigFloat,d::Base.MPFR.BigFloat,e::Base.MPFR.BigFloat) at mpfr.jl:331 +(x::Irrational{sym},y::Irrational{sym}) at constants.jl:71 +{T<:Number}(x::T<:Number,y::T<:Number) at promotion.jl:205 - +{T<:FloatingPoint}(x::Bool,y::T<:FloatingPoint) at bool.jl:43 + +{T<:AbstractFloat}(x::Bool,y::T<:AbstractFloat) at bool.jl:43 +(x::Number,y::Number) at promotion.jl:167 +(x::Integer,y::Ptr{T}) at pointer.jl:70 +(x::Bool,A::AbstractArray{Bool,N}) at array.jl:829 +(x::Integer,y::Char) at char.jl:41 +(x::Number) at operators.jl:72 +(r1::OrdinalRange{T,S},r2::OrdinalRange{T,S}) at operators.jl:325 - +{T<:FloatingPoint}(r1::FloatRange{T<:FloatingPoint},r2::FloatRange{T<:FloatingPoint}) at operators.jl:331 - +(r1::FloatRange{T<:FloatingPoint},r2::FloatRange{T<:FloatingPoint}) at operators.jl:348 - +(r1::FloatRange{T<:FloatingPoint},r2::OrdinalRange{T,S}) at operators.jl:349 - +(r1::OrdinalRange{T,S},r2::FloatRange{T<:FloatingPoint}) at operators.jl:350 + +{T<:AbstractFloat}(r1::FloatRange{T<:AbstractFloat},r2::FloatRange{T<:AbstractFloat}) at operators.jl:331 + +(r1::FloatRange{T<:AbstractFloat},r2::FloatRange{T<:AbstractFloat}) at operators.jl:348 + +(r1::FloatRange{T<:AbstractFloat},r2::OrdinalRange{T,S}) at operators.jl:349 + +(r1::OrdinalRange{T,S},r2::FloatRange{T<:AbstractFloat}) at operators.jl:350 +(x::Ptr{T},y::Integer) at pointer.jl:68 +{S,T}(A::Range{S},B::Range{T}) at array.jl:773 +{S,T}(A::Range{S},B::AbstractArray{T,N}) at array.jl:791 diff --git a/doc/manual/types.rst b/doc/manual/types.rst index 775c2b3857ef8..81fea8ace7cbb 100644 --- a/doc/manual/types.rst +++ b/doc/manual/types.rst @@ -100,8 +100,8 @@ exception is thrown, otherwise, the left-hand value is returned: .. doctest:: - julia> (1+2)::FloatingPoint - ERROR: TypeError: typeassert: expected FloatingPoint, got Int64 + julia> (1+2)::AbstractFloat + ERROR: TypeError: typeassert: expected AbstractFloat, got Int64 julia> (1+2)::Int 3 @@ -206,7 +206,7 @@ hierarchy:: abstract Number abstract Real <: Number - abstract FloatingPoint <: Real + abstract AbstractFloat <: Real abstract Integer <: Real abstract Signed <: Integer abstract Unsigned <: Integer @@ -214,10 +214,10 @@ hierarchy:: The :obj:`Number` type is a direct child type of :obj:`Any`, and :obj:`Real` is its child. In turn, :obj:`Real` has two children (it has more, but only two are shown here; we'll get to the others later): :class:`Integer` and -:class:`FloatingPoint`, separating the world into representations of integers and +:class:`AbstractFloat`, separating the world into representations of integers and representations of real numbers. Representations of real numbers include, of course, floating-point types, but also include other types, -such as rationals. Hence, :class:`FloatingPoint` is a proper subtype of +such as rationals. Hence, :class:`AbstractFloat` is a proper subtype of :obj:`Real`, including only floating-point representations of real numbers. Integers are further subdivided into :obj:`Signed` and :obj:`Unsigned` varieties. @@ -233,7 +233,7 @@ subtype of its right operand: julia> Integer <: Number true - julia> Integer <: FloatingPoint + julia> Integer <: AbstractFloat false An important use of abstract types is to provide default implementations for @@ -281,9 +281,9 @@ Unlike most languages, Julia lets you declare your own bits types, rather than providing only a fixed set of built-in bits types. In fact, the standard bits types are all defined in the language itself:: - bitstype 16 Float16 <: FloatingPoint - bitstype 32 Float32 <: FloatingPoint - bitstype 64 Float64 <: FloatingPoint + bitstype 16 Float16 <: AbstractFloat + bitstype 32 Float32 <: AbstractFloat + bitstype 64 Float64 <: AbstractFloat bitstype 8 Bool <: Integer bitstype 32 Char @@ -1181,7 +1181,7 @@ true or false: julia> isa(1,Int) true - julia> isa(1,FloatingPoint) + julia> isa(1,AbstractFloat) false The :func:`typeof` function, already used throughout the manual in examples, @@ -1220,7 +1220,7 @@ Only declared types (:obj:`DataType`) have unambiguous supertypes: .. doctest:: julia> super(Float64) - FloatingPoint + AbstractFloat julia> super(Number) Any diff --git a/doc/stdlib/base.rst b/doc/stdlib/base.rst index a66c5e913d1e1..6b7fc16454b92 100644 --- a/doc/stdlib/base.rst +++ b/doc/stdlib/base.rst @@ -282,7 +282,7 @@ All Objects ERROR: InexactError() in convert at int.jl:205 - If ``T`` is a :obj:`FloatingPoint` or :obj:`Rational` type, then it will return + If ``T`` is a :obj:`AbstractFloat` or :obj:`Rational` type, then it will return the closest value to ``x`` representable by ``T``. .. doctest:: diff --git a/doc/stdlib/math.rst b/doc/stdlib/math.rst index 01f4b7a8b0e6b..7bb80d5a049cf 100644 --- a/doc/stdlib/math.rst +++ b/doc/stdlib/math.rst @@ -421,9 +421,9 @@ Mathematical Functions Inexact equality comparison - behaves slightly different depending on types of input args: - * For ``FloatingPoint`` numbers, ``isapprox`` returns ``true`` if ``abs(x-y) <= atol + rtol*max(abs(x), abs(y))``. + * For ``AbstractFloat`` numbers, ``isapprox`` returns ``true`` if ``abs(x-y) <= atol + rtol*max(abs(x), abs(y))``. - * For ``Integer`` and ``Rational`` numbers, ``isapprox`` returns ``true`` if ``abs(x-y) <= atol``. The `rtol` argument is ignored. If one of ``x`` and ``y`` is ``FloatingPoint``, the other is promoted, and the method above is called instead. + * For ``Integer`` and ``Rational`` numbers, ``isapprox`` returns ``true`` if ``abs(x-y) <= atol``. The `rtol` argument is ignored. If one of ``x`` and ``y`` is ``AbstractFloat``, the other is promoted, and the method above is called instead. * For ``Complex`` numbers, the distance in the complex plane is compared, using the same criterion as above. diff --git a/doc/stdlib/numbers.rst b/doc/stdlib/numbers.rst index 78facf21bd2c0..d7f103dbfbd2a 100644 --- a/doc/stdlib/numbers.rst +++ b/doc/stdlib/numbers.rst @@ -72,7 +72,7 @@ Data Formats .. function:: float(x) - Convert a number, array, or string to a ``FloatingPoint`` data type. For numeric data, the smallest suitable ``FloatingPoint`` type is used. Converts strings to ``Float64``. + Convert a number, array, or string to a ``AbstractFloat`` data type. For numeric data, the smallest suitable ``AbstractFloat`` type is used. Converts strings to ``Float64``. .. function:: significand(x) @@ -209,7 +209,7 @@ General Number Functions and Constants Get the next floating point number in lexicographic order -.. function:: prevfloat(f) -> FloatingPoint +.. function:: prevfloat(f) -> AbstractFloat Get the previous floating point number in lexicographic order @@ -440,7 +440,7 @@ BigFloats --------- The `BigFloat` type implements arbitrary-precision floating-point arithmetic using the `GNU MPFR library `_. -.. function:: precision(num::FloatingPoint) +.. function:: precision(num::AbstractFloat) Get the precision of a floating point number, as defined by the effective number of bits in the mantissa. diff --git a/src/init.c b/src/init.c index 5b2add3798a7b..0b5f59f2a24b4 100644 --- a/src/init.c +++ b/src/init.c @@ -1364,7 +1364,7 @@ void jl_get_builtin_hooks(void) jl_float32_type = (jl_datatype_t*)core("Float32"); jl_float64_type = (jl_datatype_t*)core("Float64"); - jl_floatingpoint_type = (jl_datatype_t*)core("FloatingPoint"); + jl_floatingpoint_type = (jl_datatype_t*)core("AbstractFloat"); jl_number_type = (jl_datatype_t*)core("Number"); jl_signed_type = (jl_datatype_t*)core("Signed"); diff --git a/test/char.jl b/test/char.jl index 2bf06c04be822..81f07205a024e 100644 --- a/test/char.jl +++ b/test/char.jl @@ -161,4 +161,4 @@ testarrays = [numberchars; lowerchars; upperchars; plane1_playingcards; plane2_c @test isless(131071, x) == true end -end #end of let block \ No newline at end of file +end #end of let block diff --git a/test/core.jl b/test/core.jl index b500f7ab0b7df..d4f7909c2bb4a 100644 --- a/test/core.jl +++ b/test/core.jl @@ -806,7 +806,7 @@ end # issue #1153 type SI{m, s, kg} - value::FloatingPoint + value::AbstractFloat end import Base.* @@ -2073,10 +2073,10 @@ end # issue #8851 abstract AbstractThing{T,N} -type ConcreteThing{T<:FloatingPoint,N} <: AbstractThing{T,N} +type ConcreteThing{T<:AbstractFloat,N} <: AbstractThing{T,N} end -testintersect(AbstractThing{TypeVar(:T,true),2}, ConcreteThing, ConcreteThing{TypeVar(:T,FloatingPoint),2}, isequal) +testintersect(AbstractThing{TypeVar(:T,true),2}, ConcreteThing, ConcreteThing{TypeVar(:T,AbstractFloat),2}, isequal) # issue #8978 module I8978 diff --git a/test/linalg/dense.jl b/test/linalg/dense.jl index a8ef087c52620..ca9aed280c307 100644 --- a/test/linalg/dense.jl +++ b/test/linalg/dense.jl @@ -3,4 +3,4 @@ using Base.Test # Check that non-floats are correctly promoted -@test_approx_eq [1 0 0; 0 1 0]\[1,1] [1;1;0] \ No newline at end of file +@test_approx_eq [1 0 0; 0 1 0]\[1,1] [1;1;0] diff --git a/test/linalg/generic.jl b/test/linalg/generic.jl index 67752a2ffe031..a33a90013e57a 100644 --- a/test/linalg/generic.jl +++ b/test/linalg/generic.jl @@ -28,4 +28,4 @@ for elty in (Int, Rational{BigInt}, Float32, Float64, BigFloat, Complex{Float32} @test_throws DomainError logdet(convert(Matrix{elty}, -eye(n))) @test logabsdet(convert(Matrix{elty}, -eye(n)))[2] == -1 end -end \ No newline at end of file +end diff --git a/test/linalg2.jl b/test/linalg2.jl index 17c15051638ad..4bdfeef1d588c 100644 --- a/test/linalg2.jl +++ b/test/linalg2.jl @@ -315,7 +315,7 @@ for elty in (Float32, Float64, BigFloat, Complex{Float32}, Complex{Float64}, Com end # issue #10234 - if elty <: FloatingPoint || elty <: Complex + if elty <: AbstractFloat || elty <: Complex let z = zeros(elty, 100) z[1] = -Inf for p in [-2,-1.5,-1,-0.5,0.5,1,1.5,2,Inf] diff --git a/test/mpfr.jl b/test/mpfr.jl index 7e0ee20a702a1..714efe07e1659 100644 --- a/test/mpfr.jl +++ b/test/mpfr.jl @@ -145,8 +145,8 @@ y = BigFloat(1) @test typeof(convert(BigFloat, Float32(0.5))) == BigFloat @test convert(BigFloat, parse(BigInt,"9223372036854775808")) == parse(BigFloat,"9223372036854775808") @test typeof(convert(BigFloat, parse(BigInt,"9223372036854775808"))) == BigFloat -@test convert(FloatingPoint, parse(BigInt,"9223372036854775808")) == parse(BigFloat,"9223372036854775808") -@test typeof(convert(FloatingPoint, parse(BigInt,"9223372036854775808"))) == BigFloat +@test convert(AbstractFloat, parse(BigInt,"9223372036854775808")) == parse(BigFloat,"9223372036854775808") +@test typeof(convert(AbstractFloat, parse(BigInt,"9223372036854775808"))) == BigFloat # convert from @test convert(Float64, BigFloat(0.5)) == 0.5 diff --git a/test/perf/arrayalloc/lucompletepiv.py b/test/perf/arrayalloc/lucompletepiv.py index 0cd171036dcb0..81785ab307976 100644 --- a/test/perf/arrayalloc/lucompletepiv.py +++ b/test/perf/arrayalloc/lucompletepiv.py @@ -32,4 +32,4 @@ def lucompletepiv(A): print("size %4d matrix factorized in %6.3f seconds" % (n, sum(tt)/3)) -print("") \ No newline at end of file +print("") diff --git a/test/random.jl b/test/random.jl index 7142e5bf86c65..f00d4e4c8e48b 100644 --- a/test/random.jl +++ b/test/random.jl @@ -296,7 +296,7 @@ for rng in ([], [MersenneTwister()], [RandomDevice()]) a0 = rand(rng..., T) ::T a1 = rand(rng..., T, 5) ::Vector{T} a2 = rand(rng..., T, 2, 3) ::Array{T, 2} - if T <: FloatingPoint + if T <: AbstractFloat for a in [a0, a1..., a2...] @test 0.0 <= a < 1.0 end diff --git a/test/ranges.jl b/test/ranges.jl index 035eeb855ba64..edac1d2e50218 100644 --- a/test/ranges.jl +++ b/test/ranges.jl @@ -612,12 +612,12 @@ for _r in (1:2:100, 1:100, 1f0:2f0:100f0, 1.0:2.0:100.0, float_r = float(_r) big_r = big(_r) @test typeof(big_r).name === typeof(_r).name - if eltype(_r) <: FloatingPoint + if eltype(_r) <: AbstractFloat @test isa(float_r, typeof(_r)) @test eltype(big_r) === BigFloat else @test isa(float_r, Range) - @test eltype(float_r) <: FloatingPoint + @test eltype(float_r) <: AbstractFloat @test eltype(big_r) === BigInt end end diff --git a/test/reducedim.jl b/test/reducedim.jl index afa1b4f655a8a..da2d5192dccd4 100644 --- a/test/reducedim.jl +++ b/test/reducedim.jl @@ -125,7 +125,7 @@ A = [1.0 3.0 6.0; # issue #6672 @test sum(Real[1 2 3; 4 5.3 7.1], 2) == reshape([6, 16.4], 2, 1) -@test std(FloatingPoint[1,2,3], 1) == [1.0] +@test std(AbstractFloat[1,2,3], 1) == [1.0] @test sum(Any[1 2;3 4],1) == [4 6] @test sum(Vector{Int}[[1,2],[4,3]], 1)[1] == [5,5] diff --git a/test/tuple.jl b/test/tuple.jl index f2e1bc4dee939..7e37ca7504250 100644 --- a/test/tuple.jl +++ b/test/tuple.jl @@ -53,7 +53,7 @@ ## eltype ## @test eltype((1,2,3)) === Int -@test eltype((1.0,2.0,3.0)) <: FloatingPoint +@test eltype((1.0,2.0,3.0)) <: AbstractFloat @test eltype((true, false)) === Bool @test eltype((1,2.0, false)) === Any @test eltype(()) === Union{} diff --git a/test/unicode.jl b/test/unicode.jl index 862aa7cf2691d..6bdc420555e3d 100644 --- a/test/unicode.jl +++ b/test/unicode.jl @@ -4,4 +4,4 @@ include("unicode/checkstring.jl") include("unicode/utf8.jl") include("unicode/utf16.jl") include("unicode/utf32.jl") -include("unicode/utf8proc.jl") \ No newline at end of file +include("unicode/utf8proc.jl") From 2e7dbd4896df306e615720fbc5bc70dd2b1cd549 Mon Sep 17 00:00:00 2001 From: Stefan Karpinski Date: Wed, 15 Jul 2015 11:30:50 -0400 Subject: [PATCH 2/2] add deprecation definition for FloatingPoint, NEWS entry. --- NEWS.md | 3 +++ base/deprecated.jl | 3 +++ 2 files changed, 6 insertions(+) diff --git a/NEWS.md b/NEWS.md index 806f9b5155fa7..26df68f619185 100644 --- a/NEWS.md +++ b/NEWS.md @@ -92,6 +92,8 @@ Language changes * `String` is renamed to `AbstractString` ([#8872]). + * `FloatingPoint` is renamed to `AbstractFloat` ([#12162]). + * `None` is deprecated; use `Union{}` instead ([#8423]). * `Nothing` (the type of `nothing`) is renamed to `Void` ([#8423]). @@ -1542,3 +1544,4 @@ Too numerous to mention. [#12034]: https://github.com/JuliaLang/julia/issues/12034 [#12087]: https://github.com/JuliaLang/julia/issues/12087 [#12137]: https://github.com/JuliaLang/julia/issues/12137 +[#12162]: https://github.com/JuliaLang/julia/issues/12162 diff --git a/base/deprecated.jl b/base/deprecated.jl index 41ffaed5daf42..8d5b220ef0f82 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -763,3 +763,6 @@ function nonboolean_all(itr) end @deprecate iseltype(x,T) eltype(x) <: T + +const FloatingPoint = AbstractFloat +export FloatingPoint