Skip to content

Commit ce9e06e

Browse files
authored
Merge pull request #25 from JeffFessler/eps
Export `eps` and fix its definition
2 parents 48f060f + bb71cdd commit ce9e06e

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/Float8s.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module Float8s
88
(+), (-), (*), (/), (\), (^),
99
sin,cos,tan,asin,acos,atan,sinh,cosh,tanh,asinh,acosh,
1010
atanh,exp,exp2,exp10,expm1,log,log2,log10,sqrt,cbrt,log1p,
11-
atan,hypot,round,show,nextfloat,prevfloat,
11+
atan,hypot,round,show,nextfloat,prevfloat,eps,
1212
promote_rule, sign, signbit
1313

1414
export Float8, Float8_4, NaN8, Inf8, NaN8_4, Inf8_4

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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,11 @@ end
250250
@test NaN8_4 != nextfloat(NaN8_4)
251251
@test Inf8_4 == nextfloat(Inf8_4)
252252
@test -floatmax(Float8_4) == nextfloat(-Inf8_4)
253+
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
253258
end
254259

255260
@testset "Prevfloat" begin
@@ -351,4 +356,4 @@ end
351356
@test true*Float8(2) == Float8(2)
352357
@test false*Float8(2) == zero(Float8)
353358
@test 2*Float8(2) == Float8(4)
354-
end
359+
end

0 commit comments

Comments
 (0)