@@ -808,13 +808,8 @@ precision(::Type{T}; base::Integer=2) where {T<:AbstractFloat} = _precision(T, b
808808precision (:: T ; base:: Integer = 2 ) where {T<: AbstractFloat } = precision (T; base)
809809
810810
811- """
812- nextfloat(x::AbstractFloat, n::Integer)
813-
814- The result of `n` iterative applications of `nextfloat` to `x` if `n >= 0`, or `-n`
815- applications of [`prevfloat`](@ref) if `n < 0`.
816- """
817- function nextfloat (f:: IEEEFloat , d:: Integer )
811+ function _nextfloat (f:: IEEEFloat , dneg:: Bool , da:: Integer )
812+ # da must be > 0
818813 F = typeof (f)
819814 fumax = reinterpret (Unsigned, F (Inf ))
820815 U = typeof (fumax)
@@ -824,8 +819,6 @@ function nextfloat(f::IEEEFloat, d::Integer)
824819 fneg = fi < 0
825820 fu = unsigned (fi & typemax (fi))
826821
827- dneg = d < 0
828- da = uabs (d)
829822 if da > typemax (U)
830823 fneg = dneg
831824 fu = fumax
@@ -852,6 +845,14 @@ function nextfloat(f::IEEEFloat, d::Integer)
852845 reinterpret (F, fu)
853846end
854847
848+ """
849+ nextfloat(x::AbstractFloat, n::Integer)
850+
851+ The result of `n` iterative applications of `nextfloat` to `x` if `n >= 0`, or `-n`
852+ applications of [`prevfloat`](@ref) if `n < 0`.
853+ """
854+ nextfloat (f:: AbstractFloat , d:: Integer ) = _nextfloat (f, isnegative (d), uabs (d))
855+
855856"""
856857 nextfloat(x::AbstractFloat)
857858
@@ -860,23 +861,23 @@ If no such `y` exists (e.g. if `x` is `Inf` or `NaN`), then return `x`.
860861
861862See also: [`prevfloat`](@ref), [`eps`](@ref), [`issubnormal`](@ref).
862863"""
863- nextfloat (x:: AbstractFloat ) = nextfloat (x,1 )
864+ nextfloat (x:: AbstractFloat ) = nextfloat (x, 1 )
864865
865866"""
866867 prevfloat(x::AbstractFloat, n::Integer)
867868
868869The result of `n` iterative applications of `prevfloat` to `x` if `n >= 0`, or `-n`
869870applications of [`nextfloat`](@ref) if `n < 0`.
870871"""
871- prevfloat (x:: AbstractFloat , d:: Integer ) = nextfloat (x, - d )
872+ prevfloat (x:: AbstractFloat , d:: Integer ) = _nextfloat (x, ispositive (d), uabs (d) )
872873
873874"""
874875 prevfloat(x::AbstractFloat)
875876
876877Return the largest floating point number `y` of the same type as `x` such that `y < x`.
877878If no such `y` exists (e.g. if `x` is `-Inf` or `NaN`), then return `x`.
878879"""
879- prevfloat (x:: AbstractFloat ) = nextfloat (x,- 1 )
880+ prevfloat (x:: AbstractFloat ) = nextfloat (x, - 1 )
880881
881882for Ti in (Int8, Int16, Int32, Int64, Int128, UInt8, UInt16, UInt32, UInt64, UInt128)
882883 for Tf in (Float16, Float32, Float64)
0 commit comments