Skip to content

Commit bb71cdd

Browse files
committed
Use Base defs of eps
1 parent bade7db commit bb71cdd

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/float8.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ n_significant_bits(::Type{Float8_4}) = 3
3232
bias(::Type{Float8}) = 3
3333
bias(::Type{Float8_4}) = 7
3434

35-
eps(::Type{Float8}) = Float8(0x02)
36-
eps(::Type{Float8_4}) = Float8_4(0x20)
35+
eps(x::AbstractFloat8) = max(x-prevfloat(x), nextfloat(x)-x)
36+
eps(::Type{T}) where T <: AbstractFloat8 = eps(one(T))
3737

3838
# define inifinities and nan
3939
inf8(::Type{Float8}) = Float8(0x70)

test/runtests.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,10 @@ end
251251
@test Inf8_4 == nextfloat(Inf8_4)
252252
@test -floatmax(Float8_4) == nextfloat(-Inf8_4)
253253

254-
@test eps(Float8) == nextfloat(Float8(1)) - Float8(1)
254+
for T in (Float8, Float8_4)
255+
@test eps(T) == nextfloat(T(1)) - T(1)
256+
@test eps(one(T)) == eps(T)
257+
end
255258
end
256259

257260
@testset "Prevfloat" begin

0 commit comments

Comments
 (0)