Skip to content

Commit

Permalink
Fix bounds on floating point range testing (JuliaLang#48561)
Browse files Browse the repository at this point in the history
* Fix bounds on floating point range testing

Follow up on JuliaLang#48465.

Addresses CI failure noted here JuliaLang#48465 (comment).

* Use simpler error bound
  • Loading branch information
simonbyrne committed Feb 9, 2023
1 parent 7caa499 commit ec229a4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion test/ranges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,15 @@ function range_fuzztests(::Type{T}, niter, nrange) where {T}
@test m == length(r)
@test strt == first(r)
@test Δ == step(r)
@test stop last(r) atol = eps((n-1)*Δ) + eps(stop) # account for intermediate rounding in computation of stop
# potential floating point error:
# stop = strt + (n-1)*Δ
# * error <= eps((n-1)*Δ)/2 <= abs((n-1)*Δ)/2 * eps(T)
# + error <= eps(stop)/2 <= abs(stop)/2 * eps(T)
# last(r)
# rat(strt) error <= eps(strt)/2 <= abs(strt)/2 * eps(T)
# rat(Δ) error <= (n-1)*eps(Δ)/2 <= abs((n-1)*Δ)/2 * eps(T)
# T(...) error <= eps(last(r))/2 <= abs(stop)/2 * eps(T)
@test stop last(r) atol = (abs(strt)/2 + (n-1)*abs(Δ) + abs(stop)) * eps(T)
l = range(strt, stop=stop, length=n)
@test n == length(l)
@test strt == first(l)
Expand Down

0 comments on commit ec229a4

Please sign in to comment.