Skip to content

Commit

Permalink
Rename realmin/max -> floatmin/max
Browse files Browse the repository at this point in the history
  • Loading branch information
femtocleaner[bot] authored and Keno committed Jul 27, 2018
1 parent b2d3c3b commit 4ccde9a
Show file tree
Hide file tree
Showing 15 changed files with 77 additions and 77 deletions.
8 changes: 4 additions & 4 deletions base/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,8 @@ function /(z::ComplexF64, w::ComplexF64)
two = 2.0
ab = max(abs(a), abs(b))
cd = max(abs(c), abs(d))
ov = realmax(a)
un = realmin(a)
ov = floatmax(a)
un = floatmin(a)
ϵ = ulp(Float64)
bs = two/*ϵ)
s = 1.0
Expand Down Expand Up @@ -397,8 +397,8 @@ function inv(w::ComplexF64)
half = 0.5
two = 2.0
cd = max(abs(c), abs(d))
ov = realmax(c)
un = realmin(c)
ov = floatmax(c)
un = floatmin(c)
ϵ = ulp(Float64)
bs = two/*ϵ)
s = 1.0
Expand Down
4 changes: 2 additions & 2 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ export
rad2deg,
rationalize,
real,
realmax,
realmin,
floatmax,
floatmin,
reim,
reinterpret,
rem,
Expand Down
28 changes: 14 additions & 14 deletions base/float.jl
Original file line number Diff line number Diff line change
Expand Up @@ -725,14 +725,14 @@ end
typemin(x::T) where {T<:Real} = typemin(T)
typemax(x::T) where {T<:Real} = typemax(T)

realmin(::Type{Float16}) = $(bitcast(Float16, 0x0400))
realmin(::Type{Float32}) = $(bitcast(Float32, 0x00800000))
realmin(::Type{Float64}) = $(bitcast(Float64, 0x0010000000000000))
realmax(::Type{Float16}) = $(bitcast(Float16, 0x7bff))
realmax(::Type{Float32}) = $(bitcast(Float32, 0x7f7fffff))
realmax(::Type{Float64}) = $(bitcast(Float64, 0x7fefffffffffffff))

ulp(x::AbstractFloat) = isfinite(x) ? abs(x) >= realmin(x) ? ldexp(ulp(typeof(x)), exponent(x)) : nextfloat(zero(x)) : oftype(x, NaN)
floatmin(::Type{Float16}) = $(bitcast(Float16, 0x0400))
floatmin(::Type{Float32}) = $(bitcast(Float32, 0x00800000))
floatmin(::Type{Float64}) = $(bitcast(Float64, 0x0010000000000000))
floatmax(::Type{Float16}) = $(bitcast(Float16, 0x7bff))
floatmax(::Type{Float32}) = $(bitcast(Float32, 0x7f7fffff))
floatmax(::Type{Float64}) = $(bitcast(Float64, 0x7fefffffffffffff))

ulp(x::AbstractFloat) = isfinite(x) ? abs(x) >= floatmin(x) ? ldexp(ulp(typeof(x)), exponent(x)) : nextfloat(zero(x)) : oftype(x, NaN)
ulp(::Type{Float16}) = $(bitcast(Float16, 0x1400))
ulp(::Type{Float32}) = $(bitcast(Float32, 0x34000000))
ulp(::Type{Float64}) = $(bitcast(Float64, 0x3cb0000000000000))
Expand All @@ -745,7 +745,7 @@ end
The smallest in absolute value non-subnormal value representable by the given
floating-point DataType `T`.
"""
realmin(x::T) where {T<:AbstractFloat} = realmin(T)
floatmin(x::T) where {T<:AbstractFloat} = floatmin(T)

"""
realmax(T)
Expand All @@ -754,17 +754,17 @@ The highest finite value representable by the given floating-point DataType `T`.
# Examples
```jldoctest
julia> realmax(Float16)
julia> floatmax(Float16)
Float16(6.55e4)
julia> realmax(Float32)
julia> floatmax(Float32)
3.4028235f38
```
"""
realmax(x::T) where {T<:AbstractFloat} = realmax(T)
floatmax(x::T) where {T<:AbstractFloat} = floatmax(T)

realmin() = realmin(Float64)
realmax() = realmax(Float64)
floatmin() = floatmin(Float64)
floatmax() = floatmax(Float64)

"""
ulp(::Type{T}) where T<:AbstractFloat
Expand Down
6 changes: 3 additions & 3 deletions base/mpfr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import
log1p,
ulp, signbit, sin, cos, sincos, tan, sec, csc, cot, acos, asin, atan,
cosh, sinh, tanh, sech, csch, coth, acosh, asinh, atanh,
cbrt, typemax, typemin, unsafe_trunc, realmin, realmax, rounding,
cbrt, typemax, typemin, unsafe_trunc, floatmin, floatmax, rounding,
setrounding, maxintfloat, widen, significand, frexp, tryparse, iszero,
isone, big, _string_n

Expand Down Expand Up @@ -881,8 +881,8 @@ end

ulp(::Type{BigFloat}) = nextfloat(BigFloat(1)) - BigFloat(1)

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

"""
setprecision(f::Function, [T=BigFloat,] precision::Integer)
Expand Down
2 changes: 1 addition & 1 deletion base/special/cbrt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ These implementations assume that NaNs, infinities and zeros have already been f
k = significand_bits(T) - (8*sizeof(T) - 32)

u = highword(x) & 0x7fff_ffff
if u >= Base.Math.highword(realmin(T))
if u >= Base.Math.highword(floatmin(T))
v = div(u, UInt32(3)) + floor(UInt32, adj * exp2(k))
else
# subnormal
Expand Down
2 changes: 1 addition & 1 deletion base/twiceprecision.jl
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ function _linspace(start::T, stop::T, len::Integer) where {T<:IEEEFloat}
end
# 2x calculations to get high precision endpoint matching while also
# preventing overflow in ref_hi+(i-offset)*step_hi
m, k = prevfloat(realmax(T)), max(imin-1, len-imin)
m, k = prevfloat(floatmax(T)), max(imin-1, len-imin)
step_hi_pre = clamp(step, max(-(m+ref)/k, (-m+ref)/k), min((m-ref)/k, (m+ref)/k))
nb = nbitslen(T, len, imin)
step_hi = truncbits(step_hi_pre, nb)
Expand Down
4 changes: 2 additions & 2 deletions stdlib/LinearAlgebra/src/givens.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Base.copy(aR::Adjoint{<:Any,Rotation{T}}) where {T} = Rotation{T}(reverse!([r' f

realmin2(::Type{Float32}) = reinterpret(Float32, 0x26000000)
realmin2(::Type{Float64}) = reinterpret(Float64, 0x21a0000000000000)
realmin2(::Type{T}) where {T} = (twopar = 2one(T); twopar^trunc(Integer,log(realmin(T)/ulp(T))/log(twopar)/twopar))
realmin2(::Type{T}) where {T} = (twopar = 2one(T); twopar^trunc(Integer,log(floatmin(T)/ulp(T))/log(twopar)/twopar))

# derived from LAPACK's dlartg
# Copyright:
Expand Down Expand Up @@ -152,7 +152,7 @@ function givensAlgorithm(f::Complex{T}, g::Complex{T}) where T<:AbstractFloat
czero = complex(zeropar)

abs1(ff) = max(abs(real(ff)), abs(imag(ff)))
safmin = realmin(T0)
safmin = floatmin(T0)
safmn2 = realmin2(T0)
safmn2u = realmin2(T)
safmx2 = one(T)/safmn2
Expand Down
12 changes: 6 additions & 6 deletions stdlib/LinearAlgebra/test/pinv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,24 +160,24 @@ end

if eltya <: LinearAlgebra.BlasReal
@testset "sub-normal numbers/vectors/matrices" begin
a = pinv(realmin(eltya)/100)
a = pinv(floatmin(eltya)/100)
@test a 0.0
# Complex subnormal
a = pinv(realmin(eltya)/100*(1+1im))
a = pinv(floatmin(eltya)/100*(1+1im))
@test a 0.0

a = pinv([realmin(eltya); realmin(eltya)]/100)
a = pinv([floatmin(eltya); floatmin(eltya)]/100)
@test a[1] 0.0
@test a[2] 0.0
# Complex subnormal
a = pinv([realmin(eltya); realmin(eltya)]/100*(1+1im))
a = pinv([floatmin(eltya); floatmin(eltya)]/100*(1+1im))
@test a[1] 0.0
@test a[2] 0.0
a = pinv(Diagonal([realmin(eltya); realmin(eltya)]/100))
a = pinv(Diagonal([floatmin(eltya); floatmin(eltya)]/100))
@test a.diag[1] 0.0
@test a.diag[2] 0.0
# Complex subnormal
a = pinv(Diagonal([realmin(eltya); realmin(eltya)]/100*(1+1im)))
a = pinv(Diagonal([floatmin(eltya); floatmin(eltya)]/100*(1+1im)))
@test a.diag[1] 0.0
@test a.diag[2] 0.0
end
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Statistics/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using Test: guardsrand
@testset "middle" begin
@test middle(3) === 3.0
@test middle(2, 3) === 2.5
let x = ((realmax(1.0)/4)*3)
let x = ((floatmax(1.0)/4)*3)
@test middle(x, x) === x
end
@test middle(1:8) === 4.5
Expand Down
4 changes: 2 additions & 2 deletions test/grisu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1278,14 +1278,14 @@ fill!(buffer,0)
map(x->Grisu.Bignums.zero!(x),bignums)

#Float16
min_double = realmin(Float16)
min_double = floatmin(Float16)
status,len,point = Grisu.fastshortest(min_double,buffer)
@test status
@test "6104" == trimrep(buffer)
@test -4 == point
fill!(buffer,0)

max_double = realmax(Float16)
max_double = floatmax(Float16)
status,len,point = Grisu.fastshortest(max_double,buffer)
@test status
@test "655" == trimrep(buffer)
Expand Down
34 changes: 17 additions & 17 deletions test/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ end
end

for (a,b) in [(T(12.8),T(0.8)),
(prevfloat(realmin(T)), prevfloat(one(T), 2)),
(prevfloat(realmin(T)), prevfloat(one(T), 2)),
(prevfloat(realmin(T)), nextfloat(one(T), -2)),
(prevfloat(floatmin(T)), prevfloat(one(T), 2)),
(prevfloat(floatmin(T)), prevfloat(one(T), 2)),
(prevfloat(floatmin(T)), nextfloat(one(T), -2)),
(nextfloat(zero(T), 3), T(0.75)),
(prevfloat(zero(T), -3), T(0.75)),
(nextfloat(zero(T)), T(0.5))]
Expand Down Expand Up @@ -94,8 +94,8 @@ end
@test ldexp(T(-0.854375), 5) === T(-27.34)
@test ldexp(T(1.0), typemax(Int)) === T(Inf)
@test ldexp(T(1.0), typemin(Int)) === T(0.0)
@test ldexp(prevfloat(realmin(T)), typemax(Int)) === T(Inf)
@test ldexp(prevfloat(realmin(T)), typemin(Int)) === T(0.0)
@test ldexp(prevfloat(floatmin(T)), typemax(Int)) === T(Inf)
@test ldexp(prevfloat(floatmin(T)), typemin(Int)) === T(0.0)

@test ldexp(T(0.0), Int128(0)) === T(0.0)
@test ldexp(T(-0.0), Int128(0)) === T(-0.0)
Expand All @@ -104,8 +104,8 @@ end
@test ldexp(T(-0.854375), Int128(5)) === T(-27.34)
@test ldexp(T(1.0), typemax(Int128)) === T(Inf)
@test ldexp(T(1.0), typemin(Int128)) === T(0.0)
@test ldexp(prevfloat(realmin(T)), typemax(Int128)) === T(Inf)
@test ldexp(prevfloat(realmin(T)), typemin(Int128)) === T(0.0)
@test ldexp(prevfloat(floatmin(T)), typemax(Int128)) === T(Inf)
@test ldexp(prevfloat(floatmin(T)), typemin(Int128)) === T(0.0)

@test ldexp(T(0.0), BigInt(0)) === T(0.0)
@test ldexp(T(-0.0), BigInt(0)) === T(-0.0)
Expand All @@ -114,18 +114,18 @@ end
@test ldexp(T(-0.854375), BigInt(5)) === T(-27.34)
@test ldexp(T(1.0), BigInt(typemax(Int128))) === T(Inf)
@test ldexp(T(1.0), BigInt(typemin(Int128))) === T(0.0)
@test ldexp(prevfloat(realmin(T)), BigInt(typemax(Int128))) === T(Inf)
@test ldexp(prevfloat(realmin(T)), BigInt(typemin(Int128))) === T(0.0)
@test ldexp(prevfloat(floatmin(T)), BigInt(typemax(Int128))) === T(Inf)
@test ldexp(prevfloat(floatmin(T)), BigInt(typemin(Int128))) === T(0.0)

# Test also against BigFloat reference. Needs to be exactly rounded.
@test ldexp(realmin(T), -1) == T(ldexp(big(realmin(T)), -1))
@test ldexp(realmin(T), -2) == T(ldexp(big(realmin(T)), -2))
@test ldexp(realmin(T)/2, 0) == T(ldexp(big(realmin(T)/2), 0))
@test ldexp(realmin(T)/3, 0) == T(ldexp(big(realmin(T)/3), 0))
@test ldexp(realmin(T)/3, -1) == T(ldexp(big(realmin(T)/3), -1))
@test ldexp(realmin(T)/3, 11) == T(ldexp(big(realmin(T)/3), 11))
@test ldexp(realmin(T)/11, -10) == T(ldexp(big(realmin(T)/11), -10))
@test ldexp(-realmin(T)/11, -10) == T(ldexp(big(-realmin(T)/11), -10))
@test ldexp(floatmin(T), -1) == T(ldexp(big(floatmin(T)), -1))
@test ldexp(floatmin(T), -2) == T(ldexp(big(floatmin(T)), -2))
@test ldexp(floatmin(T)/2, 0) == T(ldexp(big(floatmin(T)/2), 0))
@test ldexp(floatmin(T)/3, 0) == T(ldexp(big(floatmin(T)/3), 0))
@test ldexp(floatmin(T)/3, -1) == T(ldexp(big(floatmin(T)/3), -1))
@test ldexp(floatmin(T)/3, 11) == T(ldexp(big(floatmin(T)/3), 11))
@test ldexp(floatmin(T)/11, -10) == T(ldexp(big(floatmin(T)/11), -10))
@test ldexp(-floatmin(T)/11, -10) == T(ldexp(big(-floatmin(T)/11), -10))
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions test/mpfr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import Base.MPFR
@test typeof(BigFloat(typemax(UInt64))) == BigFloat
@test typeof(BigFloat(typemax(UInt128))) == BigFloat

@test typeof(BigFloat(realmax(Float32))) == BigFloat
@test typeof(BigFloat(realmax(Float64))) == BigFloat
@test typeof(BigFloat(floatmax(Float32))) == BigFloat
@test typeof(BigFloat(floatmax(Float64))) == BigFloat

@test typeof(BigFloat(BigInt(1))) == BigFloat
@test typeof(BigFloat(BigFloat(1))) == BigFloat
Expand Down Expand Up @@ -649,10 +649,10 @@ end
@test ulp(BigFloat) == ulp(BigFloat(1))
end
@testset "realmin/realmax" begin
x = realmin(BigFloat)
x = floatmin(BigFloat)
@test x > 0
@test prevfloat(x) == 0
x = realmax(BigFloat)
x = floatmax(BigFloat)
@test !isinf(x)
@test isinf(nextfloat(x))
end
Expand Down
16 changes: 8 additions & 8 deletions test/numbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1585,10 +1585,10 @@ end
@test ulp(-float(0)) == 5e-324
@test ulp(nextfloat(float(0))) == 5e-324
@test ulp(-nextfloat(float(0))) == 5e-324
@test ulp(realmin()) == 5e-324
@test ulp(-realmin()) == 5e-324
@test ulp(realmax()) == 2.0^(1023-52)
@test ulp(-realmax()) == 2.0^(1023-52)
@test ulp(floatmin()) == 5e-324
@test ulp(-floatmin()) == 5e-324
@test ulp(floatmax()) == 2.0^(1023-52)
@test ulp(-floatmax()) == 2.0^(1023-52)
@test isnan(ulp(NaN))
@test isnan(ulp(Inf))
@test isnan(ulp(-Inf))
Expand Down Expand Up @@ -1786,8 +1786,8 @@ end
@test 0x1p-52 == ulp()
@test 0x1p-52 + 1 != 1
@test 0x1p-53 + 1 == 1
@test 0x1p-1022 == realmin()
@test 0x1.fffffffffffffp1023 == realmax()
@test 0x1p-1022 == floatmin()
@test 0x1.fffffffffffffp1023 == floatmax()
@test isinf(nextfloat(0x1.fffffffffffffp1023))
end
@testset "issue #1308" begin
Expand Down Expand Up @@ -1985,8 +1985,8 @@ for F in (Float16,Float32,Float64)
@test reinterpret(Signed,one(F)) === signed(Base.exponent_one(F))
end

@test ulp(realmax(Float64)) == 1.99584030953472e292
@test ulp(-realmax(Float64)) == 1.99584030953472e292
@test ulp(floatmax(Float64)) == 1.99584030953472e292
@test ulp(-floatmax(Float64)) == 1.99584030953472e292

# modular multiplicative inverses of odd numbers via exponentiation

Expand Down
8 changes: 4 additions & 4 deletions test/ranges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ isdefined(Main, :TestHelpers) || @eval Main include(joinpath(dirname(@__FILE__),
# precision compared to widening.
function cmp_sn(w, hi, lo, slopbits=0)
if !isfinite(hi)
if abs(w) > realmax(typeof(hi))
if abs(w) > floatmax(typeof(hi))
return isinf(hi) && sign(w) == sign(hi)
end
if isnan(w) && isnan(hi)
Expand Down Expand Up @@ -121,7 +121,7 @@ astuple(x) = (x.hi, x.lo)

function cmp_sn2(w, hi, lo, slopbits=0)
if !isfinite(hi)
if abs(w) > realmax(typeof(hi))
if abs(w) > floatmax(typeof(hi))
return isinf(hi) && sign(w) == sign(hi)
end
if isnan(w) && isnan(hi)
Expand Down Expand Up @@ -670,11 +670,11 @@ end

@testset "range with very large endpoints for type $T" for T = (Float32, Float64)
largeint = Int(min(maxintfloat(T), typemax(Int)))
a = realmax()
a = floatmax()
for i = 1:5
@test [range(a, stop=a, length=1);] == [a]
@test [range(-a, stop=-a, length=1);] == [-a]
b = realmax()
b = floatmax()
for j = 1:5
@test [range(-a, stop=b, length=0);] == []
@test [range(-a, stop=b, length=2);] == [-a,b]
Expand Down
16 changes: 8 additions & 8 deletions test/rational.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ using Test
@test 0.1 == 3602879701896397//36028797018963968
@test Inf == 1//0 == 2//0 == typemax(Int)//0
@test -Inf == -1//0 == -2//0 == -typemax(Int)//0
@test realmin() != 1//(BigInt(2)^1022+1)
@test realmin() == 1//(BigInt(2)^1022)
@test realmin() != 1//(BigInt(2)^1022-1)
@test realmin()/2 != 1//(BigInt(2)^1023+1)
@test realmin()/2 == 1//(BigInt(2)^1023)
@test realmin()/2 != 1//(BigInt(2)^1023-1)
@test floatmin() != 1//(BigInt(2)^1022+1)
@test floatmin() == 1//(BigInt(2)^1022)
@test floatmin() != 1//(BigInt(2)^1022-1)
@test floatmin()/2 != 1//(BigInt(2)^1023+1)
@test floatmin()/2 == 1//(BigInt(2)^1023)
@test floatmin()/2 != 1//(BigInt(2)^1023-1)
@test nextfloat(0.0) != 1//(BigInt(2)^1074+1)
@test nextfloat(0.0) == 1//(BigInt(2)^1074)
@test nextfloat(0.0) != 1//(BigInt(2)^1074-1)
Expand Down Expand Up @@ -283,8 +283,8 @@ end
@test convert(Rational{BigInt},zero(BigFloat)) == 0
@test convert(Rational{BigInt},-zero(BigFloat)) == 0
@test convert(Rational{BigInt},5e-324) == 5e-324
@test convert(Rational{BigInt},realmin(Float64)) == realmin(Float64)
@test convert(Rational{BigInt},realmax(Float64)) == realmax(Float64)
@test convert(Rational{BigInt},floatmin(Float64)) == floatmin(Float64)
@test convert(Rational{BigInt},floatmax(Float64)) == floatmax(Float64)

@test isa(convert(Float64, big(1)//2), Float64)
end
Expand Down

0 comments on commit 4ccde9a

Please sign in to comment.