Skip to content

Commit dc73a23

Browse files
KenoKristofferC
authored andcommitted
Rename realmin/max -> floatmin/max (#28302)
The names `realmin`/`realmax`, don't make too much sense in our terminology. These function are floating-point property queries, querying in particular the largest/smallest positive normalized floating point value. `posnormfloatmin` isn't a great name however, so simply `floatmin` was suggested. This has the advantage that it's suggestive of the fact that it's a floating point type query, even if it's not quite the minimum floating point value or even the minimum positive floating point value, but that's what docs are for. In any case, they're better than real. We have a good number of subtypes of `Real` for which these functions make no sense. In libc, these are called FLT_MIN/FLT_MAX or DBL_MIN/DBL_MAX.
1 parent 3851462 commit dc73a23

File tree

18 files changed

+95
-89
lines changed

18 files changed

+95
-89
lines changed

NEWS.md

+2
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,8 @@ Deprecated or removed
13231323

13241324
* `squeeze` is deprecated in favor of `dropdims`.
13251325

1326+
* `realmin`/`realmax` are deprecated in favor of `floatmin`/`floatmax` ([#28302]).
1327+
13261328
Command-line option changes
13271329
---------------------------
13281330

base/complex.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,8 @@ function /(z::ComplexF64, w::ComplexF64)
364364
two = 2.0
365365
ab = max(abs(a), abs(b))
366366
cd = max(abs(c), abs(d))
367-
ov = realmax(a)
368-
un = realmin(a)
367+
ov = floatmax(a)
368+
un = floatmin(a)
369369
ϵ = eps(Float64)
370370
bs = two/*ϵ)
371371
s = 1.0
@@ -397,8 +397,8 @@ function inv(w::ComplexF64)
397397
half = 0.5
398398
two = 2.0
399399
cd = max(abs(c), abs(d))
400-
ov = realmax(c)
401-
un = realmin(c)
400+
ov = floatmax(c)
401+
un = floatmin(c)
402402
ϵ = eps(Float64)
403403
bs = two/*ϵ)
404404
s = 1.0

base/deprecated.jl

+4
Original file line numberDiff line numberDiff line change
@@ -1771,6 +1771,10 @@ end
17711771
# PR #28223
17721772
@deprecate code_llvm_raw(f, types=Tuple) code_llvm(f, types; raw=true)
17731773

1774+
# PR #28302
1775+
@deprecate realmin floatmin
1776+
@deprecate realmax floatmax
1777+
17741778
# END 0.7 deprecations
17751779

17761780
# BEGIN 1.0 deprecations

base/exports.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,8 @@ export
309309
rad2deg,
310310
rationalize,
311311
real,
312-
realmax,
313-
realmin,
312+
floatmax,
313+
floatmin,
314314
reim,
315315
reinterpret,
316316
rem,

base/float.jl

+16-16
Original file line numberDiff line numberDiff line change
@@ -725,46 +725,46 @@ end
725725
typemin(x::T) where {T<:Real} = typemin(T)
726726
typemax(x::T) where {T<:Real} = typemax(T)
727727

728-
realmin(::Type{Float16}) = $(bitcast(Float16, 0x0400))
729-
realmin(::Type{Float32}) = $(bitcast(Float32, 0x00800000))
730-
realmin(::Type{Float64}) = $(bitcast(Float64, 0x0010000000000000))
731-
realmax(::Type{Float16}) = $(bitcast(Float16, 0x7bff))
732-
realmax(::Type{Float32}) = $(bitcast(Float32, 0x7f7fffff))
733-
realmax(::Type{Float64}) = $(bitcast(Float64, 0x7fefffffffffffff))
734-
735-
eps(x::AbstractFloat) = isfinite(x) ? abs(x) >= realmin(x) ? ldexp(eps(typeof(x)), exponent(x)) : nextfloat(zero(x)) : oftype(x, NaN)
728+
floatmin(::Type{Float16}) = $(bitcast(Float16, 0x0400))
729+
floatmin(::Type{Float32}) = $(bitcast(Float32, 0x00800000))
730+
floatmin(::Type{Float64}) = $(bitcast(Float64, 0x0010000000000000))
731+
floatmax(::Type{Float16}) = $(bitcast(Float16, 0x7bff))
732+
floatmax(::Type{Float32}) = $(bitcast(Float32, 0x7f7fffff))
733+
floatmax(::Type{Float64}) = $(bitcast(Float64, 0x7fefffffffffffff))
734+
735+
eps(x::AbstractFloat) = isfinite(x) ? abs(x) >= floatmin(x) ? ldexp(eps(typeof(x)), exponent(x)) : nextfloat(zero(x)) : oftype(x, NaN)
736736
eps(::Type{Float16}) = $(bitcast(Float16, 0x1400))
737737
eps(::Type{Float32}) = $(bitcast(Float32, 0x34000000))
738738
eps(::Type{Float64}) = $(bitcast(Float64, 0x3cb0000000000000))
739739
eps() = eps(Float64)
740740
end
741741

742742
"""
743-
realmin(T)
743+
floatmin(T)
744744
745745
The smallest in absolute value non-subnormal value representable by the given
746746
floating-point DataType `T`.
747747
"""
748-
realmin(x::T) where {T<:AbstractFloat} = realmin(T)
748+
floatmin(x::T) where {T<:AbstractFloat} = floatmin(T)
749749

750750
"""
751-
realmax(T)
751+
floatmax(T)
752752
753753
The highest finite value representable by the given floating-point DataType `T`.
754754
755755
# Examples
756756
```jldoctest
757-
julia> realmax(Float16)
757+
julia> floatmax(Float16)
758758
Float16(6.55e4)
759759
760-
julia> realmax(Float32)
760+
julia> floatmax(Float32)
761761
3.4028235f38
762762
```
763763
"""
764-
realmax(x::T) where {T<:AbstractFloat} = realmax(T)
764+
floatmax(x::T) where {T<:AbstractFloat} = floatmax(T)
765765

766-
realmin() = realmin(Float64)
767-
realmax() = realmax(Float64)
766+
floatmin() = floatmin(Float64)
767+
floatmax() = floatmax(Float64)
768768

769769
"""
770770
eps(::Type{T}) where T<:AbstractFloat

base/mpfr.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import
1515
log1p,
1616
eps, signbit, sin, cos, sincos, tan, sec, csc, cot, acos, asin, atan,
1717
cosh, sinh, tanh, sech, csch, coth, acosh, asinh, atanh,
18-
cbrt, typemax, typemin, unsafe_trunc, realmin, realmax, rounding,
18+
cbrt, typemax, typemin, unsafe_trunc, floatmin, floatmax, rounding,
1919
setrounding, maxintfloat, widen, significand, frexp, tryparse, iszero,
2020
isone, big, _string_n
2121

@@ -881,8 +881,8 @@ end
881881

882882
eps(::Type{BigFloat}) = nextfloat(BigFloat(1)) - BigFloat(1)
883883

884-
realmin(::Type{BigFloat}) = nextfloat(zero(BigFloat))
885-
realmax(::Type{BigFloat}) = prevfloat(BigFloat(Inf))
884+
floatmin(::Type{BigFloat}) = nextfloat(zero(BigFloat))
885+
floatmax(::Type{BigFloat}) = prevfloat(BigFloat(Inf))
886886

887887
"""
888888
setprecision(f::Function, [T=BigFloat,] precision::Integer)

base/special/cbrt.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ These implementations assume that NaNs, infinities and zeros have already been f
6565
k = significand_bits(T) - (8*sizeof(T) - 32)
6666

6767
u = highword(x) & 0x7fff_ffff
68-
if u >= Base.Math.highword(realmin(T))
68+
if u >= Base.Math.highword(floatmin(T))
6969
v = div(u, UInt32(3)) + floor(UInt32, adj * exp2(k))
7070
else
7171
# subnormal

base/twiceprecision.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ function _linspace(start::T, stop::T, len::Integer) where {T<:IEEEFloat}
622622
end
623623
# 2x calculations to get high precision endpoint matching while also
624624
# preventing overflow in ref_hi+(i-offset)*step_hi
625-
m, k = prevfloat(realmax(T)), max(imin-1, len-imin)
625+
m, k = prevfloat(floatmax(T)), max(imin-1, len-imin)
626626
step_hi_pre = clamp(step, max(-(m+ref)/k, (-m+ref)/k), min((m-ref)/k, (m+ref)/k))
627627
nb = nbitslen(T, len, imin)
628628
step_hi = truncbits(step_hi_pre, nb)

doc/src/base/base.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ Base.datatype_pointerfree
162162
```@docs
163163
Base.typemin
164164
Base.typemax
165-
Base.realmin
166-
Base.realmax
165+
Base.floatmin
166+
Base.floatmax
167167
Base.maxintfloat
168168
Base.eps(::Type{<:AbstractFloat})
169169
Base.eps(::AbstractFloat)

stdlib/LinearAlgebra/src/givens.jl

+8-8
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ function Base.copy(aG::Adjoint{<:Any,<:Givens})
6161
end
6262
Base.copy(aR::Adjoint{<:Any,Rotation{T}}) where {T} = Rotation{T}(reverse!([r' for r in aR.parent.rotations]))
6363

64-
realmin2(::Type{Float32}) = reinterpret(Float32, 0x26000000)
65-
realmin2(::Type{Float64}) = reinterpret(Float64, 0x21a0000000000000)
66-
realmin2(::Type{T}) where {T} = (twopar = 2one(T); twopar^trunc(Integer,log(realmin(T)/eps(T))/log(twopar)/twopar))
64+
floatmin2(::Type{Float32}) = reinterpret(Float32, 0x26000000)
65+
floatmin2(::Type{Float64}) = reinterpret(Float64, 0x21a0000000000000)
66+
floatmin2(::Type{T}) where {T} = (twopar = 2one(T); twopar^trunc(Integer,log(floatmin(T)/eps(T))/log(twopar)/twopar))
6767

6868
# derived from LAPACK's dlartg
6969
# Copyright:
@@ -78,8 +78,8 @@ function givensAlgorithm(f::T, g::T) where T<:AbstractFloat
7878
zeropar = T0(zero(T)) # must be dimensionless
7979

8080
# need both dimensionful and dimensionless versions of these:
81-
safmn2 = realmin2(T0)
82-
safmn2u = realmin2(T)
81+
safmn2 = floatmin2(T0)
82+
safmn2u = floatmin2(T)
8383
safmx2 = one(T)/safmn2
8484
safmx2u = oneunit(T)/safmn2
8585

@@ -152,9 +152,9 @@ function givensAlgorithm(f::Complex{T}, g::Complex{T}) where T<:AbstractFloat
152152
czero = complex(zeropar)
153153

154154
abs1(ff) = max(abs(real(ff)), abs(imag(ff)))
155-
safmin = realmin(T0)
156-
safmn2 = realmin2(T0)
157-
safmn2u = realmin2(T)
155+
safmin = floatmin(T0)
156+
safmn2 = floatmin2(T0)
157+
safmn2u = floatmin2(T)
158158
safmx2 = one(T)/safmn2
159159
safmx2u = oneunit(T)/safmn2
160160
scalepar = max(abs1(f), abs1(g))

stdlib/LinearAlgebra/test/pinv.jl

+6-6
Original file line numberDiff line numberDiff line change
@@ -160,24 +160,24 @@ end
160160

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

169-
a = pinv([realmin(eltya); realmin(eltya)]/100)
169+
a = pinv([floatmin(eltya); floatmin(eltya)]/100)
170170
@test a[1] 0.0
171171
@test a[2] 0.0
172172
# Complex subnormal
173-
a = pinv([realmin(eltya); realmin(eltya)]/100*(1+1im))
173+
a = pinv([floatmin(eltya); floatmin(eltya)]/100*(1+1im))
174174
@test a[1] 0.0
175175
@test a[2] 0.0
176-
a = pinv(Diagonal([realmin(eltya); realmin(eltya)]/100))
176+
a = pinv(Diagonal([floatmin(eltya); floatmin(eltya)]/100))
177177
@test a.diag[1] 0.0
178178
@test a.diag[2] 0.0
179179
# Complex subnormal
180-
a = pinv(Diagonal([realmin(eltya); realmin(eltya)]/100*(1+1im)))
180+
a = pinv(Diagonal([floatmin(eltya); floatmin(eltya)]/100*(1+1im)))
181181
@test a.diag[1] 0.0
182182
@test a.diag[2] 0.0
183183
end

stdlib/Statistics/test/runtests.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ using Test: guardsrand
66
@testset "middle" begin
77
@test middle(3) === 3.0
88
@test middle(2, 3) === 2.5
9-
let x = ((realmax(1.0)/4)*3)
9+
let x = ((floatmax(1.0)/4)*3)
1010
@test middle(x, x) === x
1111
end
1212
@test middle(1:8) === 4.5

test/grisu.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1278,14 +1278,14 @@ fill!(buffer,0)
12781278
map(x->Grisu.Bignums.zero!(x),bignums)
12791279

12801280
#Float16
1281-
min_double = realmin(Float16)
1281+
min_double = floatmin(Float16)
12821282
status,len,point = Grisu.fastshortest(min_double,buffer)
12831283
@test status
12841284
@test "6104" == trimrep(buffer)
12851285
@test -4 == point
12861286
fill!(buffer,0)
12871287

1288-
max_double = realmax(Float16)
1288+
max_double = floatmax(Float16)
12891289
status,len,point = Grisu.fastshortest(max_double,buffer)
12901290
@test status
12911291
@test "655" == trimrep(buffer)

test/math.jl

+17-17
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ end
5656
end
5757

5858
for (a,b) in [(T(12.8),T(0.8)),
59-
(prevfloat(realmin(T)), prevfloat(one(T), 2)),
60-
(prevfloat(realmin(T)), prevfloat(one(T), 2)),
61-
(prevfloat(realmin(T)), nextfloat(one(T), -2)),
59+
(prevfloat(floatmin(T)), prevfloat(one(T), 2)),
60+
(prevfloat(floatmin(T)), prevfloat(one(T), 2)),
61+
(prevfloat(floatmin(T)), nextfloat(one(T), -2)),
6262
(nextfloat(zero(T), 3), T(0.75)),
6363
(prevfloat(zero(T), -3), T(0.75)),
6464
(nextfloat(zero(T)), T(0.5))]
@@ -94,8 +94,8 @@ end
9494
@test ldexp(T(-0.854375), 5) === T(-27.34)
9595
@test ldexp(T(1.0), typemax(Int)) === T(Inf)
9696
@test ldexp(T(1.0), typemin(Int)) === T(0.0)
97-
@test ldexp(prevfloat(realmin(T)), typemax(Int)) === T(Inf)
98-
@test ldexp(prevfloat(realmin(T)), typemin(Int)) === T(0.0)
97+
@test ldexp(prevfloat(floatmin(T)), typemax(Int)) === T(Inf)
98+
@test ldexp(prevfloat(floatmin(T)), typemin(Int)) === T(0.0)
9999

100100
@test ldexp(T(0.0), Int128(0)) === T(0.0)
101101
@test ldexp(T(-0.0), Int128(0)) === T(-0.0)
@@ -104,8 +104,8 @@ end
104104
@test ldexp(T(-0.854375), Int128(5)) === T(-27.34)
105105
@test ldexp(T(1.0), typemax(Int128)) === T(Inf)
106106
@test ldexp(T(1.0), typemin(Int128)) === T(0.0)
107-
@test ldexp(prevfloat(realmin(T)), typemax(Int128)) === T(Inf)
108-
@test ldexp(prevfloat(realmin(T)), typemin(Int128)) === T(0.0)
107+
@test ldexp(prevfloat(floatmin(T)), typemax(Int128)) === T(Inf)
108+
@test ldexp(prevfloat(floatmin(T)), typemin(Int128)) === T(0.0)
109109

110110
@test ldexp(T(0.0), BigInt(0)) === T(0.0)
111111
@test ldexp(T(-0.0), BigInt(0)) === T(-0.0)
@@ -114,18 +114,18 @@ end
114114
@test ldexp(T(-0.854375), BigInt(5)) === T(-27.34)
115115
@test ldexp(T(1.0), BigInt(typemax(Int128))) === T(Inf)
116116
@test ldexp(T(1.0), BigInt(typemin(Int128))) === T(0.0)
117-
@test ldexp(prevfloat(realmin(T)), BigInt(typemax(Int128))) === T(Inf)
118-
@test ldexp(prevfloat(realmin(T)), BigInt(typemin(Int128))) === T(0.0)
117+
@test ldexp(prevfloat(floatmin(T)), BigInt(typemax(Int128))) === T(Inf)
118+
@test ldexp(prevfloat(floatmin(T)), BigInt(typemin(Int128))) === T(0.0)
119119

120120
# Test also against BigFloat reference. Needs to be exactly rounded.
121-
@test ldexp(realmin(T), -1) == T(ldexp(big(realmin(T)), -1))
122-
@test ldexp(realmin(T), -2) == T(ldexp(big(realmin(T)), -2))
123-
@test ldexp(realmin(T)/2, 0) == T(ldexp(big(realmin(T)/2), 0))
124-
@test ldexp(realmin(T)/3, 0) == T(ldexp(big(realmin(T)/3), 0))
125-
@test ldexp(realmin(T)/3, -1) == T(ldexp(big(realmin(T)/3), -1))
126-
@test ldexp(realmin(T)/3, 11) == T(ldexp(big(realmin(T)/3), 11))
127-
@test ldexp(realmin(T)/11, -10) == T(ldexp(big(realmin(T)/11), -10))
128-
@test ldexp(-realmin(T)/11, -10) == T(ldexp(big(-realmin(T)/11), -10))
121+
@test ldexp(floatmin(T), -1) == T(ldexp(big(floatmin(T)), -1))
122+
@test ldexp(floatmin(T), -2) == T(ldexp(big(floatmin(T)), -2))
123+
@test ldexp(floatmin(T)/2, 0) == T(ldexp(big(floatmin(T)/2), 0))
124+
@test ldexp(floatmin(T)/3, 0) == T(ldexp(big(floatmin(T)/3), 0))
125+
@test ldexp(floatmin(T)/3, -1) == T(ldexp(big(floatmin(T)/3), -1))
126+
@test ldexp(floatmin(T)/3, 11) == T(ldexp(big(floatmin(T)/3), 11))
127+
@test ldexp(floatmin(T)/11, -10) == T(ldexp(big(floatmin(T)/11), -10))
128+
@test ldexp(-floatmin(T)/11, -10) == T(ldexp(big(-floatmin(T)/11), -10))
129129
end
130130
end
131131
end

test/mpfr.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import Base.MPFR
2727
@test typeof(BigFloat(typemax(UInt64))) == BigFloat
2828
@test typeof(BigFloat(typemax(UInt128))) == BigFloat
2929

30-
@test typeof(BigFloat(realmax(Float32))) == BigFloat
31-
@test typeof(BigFloat(realmax(Float64))) == BigFloat
30+
@test typeof(BigFloat(floatmax(Float32))) == BigFloat
31+
@test typeof(BigFloat(floatmax(Float64))) == BigFloat
3232

3333
@test typeof(BigFloat(BigInt(1))) == BigFloat
3434
@test typeof(BigFloat(BigFloat(1))) == BigFloat
@@ -648,11 +648,11 @@ end
648648
@test BigFloat(1) + x == BigFloat(1) + prevfloat(x)
649649
@test eps(BigFloat) == eps(BigFloat(1))
650650
end
651-
@testset "realmin/realmax" begin
652-
x = realmin(BigFloat)
651+
@testset "floatmin/floatmax" begin
652+
x = floatmin(BigFloat)
653653
@test x > 0
654654
@test prevfloat(x) == 0
655-
x = realmax(BigFloat)
655+
x = floatmax(BigFloat)
656656
@test !isinf(x)
657657
@test isinf(nextfloat(x))
658658
end

test/numbers.jl

+9-9
Original file line numberDiff line numberDiff line change
@@ -1585,10 +1585,10 @@ end
15851585
@test eps(-float(0)) == 5e-324
15861586
@test eps(nextfloat(float(0))) == 5e-324
15871587
@test eps(-nextfloat(float(0))) == 5e-324
1588-
@test eps(realmin()) == 5e-324
1589-
@test eps(-realmin()) == 5e-324
1590-
@test eps(realmax()) == 2.0^(1023-52)
1591-
@test eps(-realmax()) == 2.0^(1023-52)
1588+
@test eps(floatmin()) == 5e-324
1589+
@test eps(-floatmin()) == 5e-324
1590+
@test eps(floatmax()) == 2.0^(1023-52)
1591+
@test eps(-floatmax()) == 2.0^(1023-52)
15921592
@test isnan(eps(NaN))
15931593
@test isnan(eps(Inf))
15941594
@test isnan(eps(-Inf))
@@ -1782,12 +1782,12 @@ end
17821782
@test 0xf.fP1 === 31.875
17831783
@test -0x1.0p2 === -4.0
17841784
end
1785-
@testset "eps / realmin / realmax" begin
1785+
@testset "eps / floatmin / floatmax" begin
17861786
@test 0x1p-52 == eps()
17871787
@test 0x1p-52 + 1 != 1
17881788
@test 0x1p-53 + 1 == 1
1789-
@test 0x1p-1022 == realmin()
1790-
@test 0x1.fffffffffffffp1023 == realmax()
1789+
@test 0x1p-1022 == floatmin()
1790+
@test 0x1.fffffffffffffp1023 == floatmax()
17911791
@test isinf(nextfloat(0x1.fffffffffffffp1023))
17921792
end
17931793
@testset "issue #1308" begin
@@ -1985,8 +1985,8 @@ for F in (Float16,Float32,Float64)
19851985
@test reinterpret(Signed,one(F)) === signed(Base.exponent_one(F))
19861986
end
19871987

1988-
@test eps(realmax(Float64)) == 1.99584030953472e292
1989-
@test eps(-realmax(Float64)) == 1.99584030953472e292
1988+
@test eps(floatmax(Float64)) == 1.99584030953472e292
1989+
@test eps(-floatmax(Float64)) == 1.99584030953472e292
19901990

19911991
# modular multiplicative inverses of odd numbers via exponentiation
19921992

0 commit comments

Comments
 (0)