Skip to content

Commit

Permalink
Merge pull request #8 from dpsanders/fix_round_nan
Browse files Browse the repository at this point in the history
Treat lo==NaN as meaning exact
  • Loading branch information
JeffreySarnoff authored Apr 28, 2017
2 parents fb1f3ad + 13131f9 commit 04a4364
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/FastRounding.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ sqrt_round{T<:SysFloat}(a::T) = sqrt(a)
To perform arithmetic with directed rounding more rapidly
we use error-free transformations to control rounding
and quick, accurate float adjacency value calculation.
=#
=#

@inline function round_errorfree{T<:SysFloat}(hi::T, lo::T, ::RoundingMode{:Nearest})::T
return hi
end
end

@inline function round_errorfree{T<:SysFloat}(hi::T, lo::T, ::RoundingMode{:ToZero})::T
return signbit(hi) != signbit(lo) ? AdjacentFloats.next_nearerto_zero(hi) : hi
Expand All @@ -72,12 +72,12 @@ end
end

@inline function round_errorfree{T<:SysFloat}(hi::T, lo::T, ::RoundingMode{:Up})::T
return lo<=zero(T) ? hi : next_float(hi)
return (lo<=zero(T) || isnan(lo)) ? hi : next_float(hi)
end

@inline function round_errorfree{T<:SysFloat}(hi::T, lo::T, ::RoundingMode{:Down})::T
return lo>=zero(T) ? hi : prev_float(hi)
return (lo>=zero(T) || isnan(lo)) ? hi : prev_float(hi)
end


end # module

0 comments on commit 04a4364

Please sign in to comment.