@@ -807,13 +807,7 @@ precision(::Type{T}; base::Integer=2) where {T<:AbstractFloat} = _precision(T, b
807807precision (:: T ; base:: Integer = 2 ) where {T<: AbstractFloat } = precision (T; base)
808808
809809
810- """
811- nextfloat(x::AbstractFloat, n::Integer)
812-
813- The result of `n` iterative applications of `nextfloat` to `x` if `n >= 0`, or `-n`
814- applications of [`prevfloat`](@ref) if `n < 0`.
815- """
816- function nextfloat (f:: IEEEFloat , d:: Integer )
810+ function _nextfloat (f:: IEEEFloat , dneg:: Bool , da:: Unsigned )
817811 F = typeof (f)
818812 fumax = reinterpret (Unsigned, F (Inf ))
819813 U = typeof (fumax)
@@ -823,8 +817,6 @@ function nextfloat(f::IEEEFloat, d::Integer)
823817 fneg = fi < 0
824818 fu = unsigned (fi & typemax (fi))
825819
826- dneg = d < 0
827- da = uabs (d)
828820 if da > typemax (U)
829821 fneg = dneg
830822 fu = fumax
@@ -851,6 +843,15 @@ function nextfloat(f::IEEEFloat, d::Integer)
851843 reinterpret (F, fu)
852844end
853845
846+ """
847+ nextfloat(x::AbstractFloat, n::Integer)
848+
849+ The result of `n` iterative applications of `nextfloat` to `x` if `n >= 0`, or `-n`
850+ applications of [`prevfloat`](@ref) if `n < 0`.
851+ """
852+ nextfloat (f:: AbstractFloat , d:: Integer ) = _nextfloat (f, d < 0 , uabs (d))
853+ nextfloat (f:: IEEEFloat , d:: Unsigned ) = _nextfloat (f, false , d)
854+
854855"""
855856 nextfloat(x::AbstractFloat)
856857
@@ -859,23 +860,23 @@ If no such `y` exists (e.g. if `x` is `Inf` or `NaN`), then return `x`.
859860
860861See also: [`prevfloat`](@ref), [`eps`](@ref), [`issubnormal`](@ref).
861862"""
862- nextfloat (x:: AbstractFloat ) = nextfloat (x,1 )
863+ nextfloat (x:: AbstractFloat ) = nextfloat (x, 1 )
863864
864865"""
865866 prevfloat(x::AbstractFloat, n::Integer)
866867
867868The result of `n` iterative applications of `prevfloat` to `x` if `n >= 0`, or `-n`
868869applications of [`nextfloat`](@ref) if `n < 0`.
869870"""
870- prevfloat (x:: AbstractFloat , d:: Integer ) = nextfloat (x, - d )
871+ prevfloat (x:: AbstractFloat , d:: Integer ) = _nextfloat (x, d > 0 , uabs (d) )
871872
872873"""
873874 prevfloat(x::AbstractFloat)
874875
875876Return the largest floating point number `y` of the same type as `x` such that `y < x`.
876877If no such `y` exists (e.g. if `x` is `-Inf` or `NaN`), then return `x`.
877878"""
878- prevfloat (x:: AbstractFloat ) = nextfloat (x,- 1 )
879+ prevfloat (x:: AbstractFloat ) = nextfloat (x, - 1 )
879880
880881for Ti in (Int8, Int16, Int32, Int64, Int128, UInt8, UInt16, UInt32, UInt64, UInt128)
881882 for Tf in (Float16, Float32, Float64)
0 commit comments