@@ -807,13 +807,8 @@ 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:: Integer )
811+     #  da must be > 0
817812    F =  typeof (f)
818813    fumax =  reinterpret (Unsigned, F (Inf ))
819814    U =  typeof (fumax)
@@ -823,8 +818,6 @@ function nextfloat(f::IEEEFloat, d::Integer)
823818    fneg =  fi <  0 
824819    fu =  unsigned (fi &  typemax (fi))
825820
826-     dneg =  d <  0 
827-     da =  uabs (d)
828821    if  da >  typemax (U)
829822        fneg =  dneg
830823        fu =  fumax
@@ -851,6 +844,14 @@ function nextfloat(f::IEEEFloat, d::Integer)
851844    reinterpret (F, fu)
852845end 
853846
847+ """ 
848+     nextfloat(x::AbstractFloat, n::Integer) 
849+ 
850+ The result of `n` iterative applications of `nextfloat` to `x` if `n >= 0`, or `-n` 
851+ applications of [`prevfloat`](@ref) if `n < 0`. 
852+ """ 
853+ nextfloat (f:: AbstractFloat , d:: Integer ) =  _nextfloat (f, isnegative (d), uabs (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, ispositive (d),  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