Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/float8.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ for op in (:+, :-, :*, :/, :\, :^)
@eval ($op)(a::Float8_4, b::Float8_4) = Float8_4(($op)(Float32(a), Float32(b)))
end

for func in (:sin,:cos,:tan,:asin,:acos,:atan,:sinh,:cosh,:tanh,:asinh,:acosh,
:atanh,:exp,:exp2,:exp10,:expm1,:log,:log2,:log10,:sqrt,:cbrt,:lgamma,:log1p)
for func in (:sin,:cos,:tan,:cis,:sinpi,:cospi,:tanpi,:cispi,:sinh,:cosh,:tanh,
:asin,:acos,:atan,:asinh,:acosh,:atanh,
:exp,:exp2,:exp10,:expm1,:log,:log2,:log10,:log1p,
:sqrt,:cbrt,:lgamma)
@eval begin
$func(a::Float8) = Float8($func(Float32(a)))
$func(a::Float8_4) = Float8_4($func(Float32(a)))
Expand Down
31 changes: 15 additions & 16 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,33 +69,32 @@ end
@testset "Conversion Float8 <-> Float32" begin

@testset for i in 0x00:0xff
if ~isnan(Float8(i))
if !isnan(Float8(i))
@test i == reinterpret(UInt8,Float8(Float32(Float8(i))))
end
end
end

# Currently not implemented
# @testset "Conversion Float8_4 <-> Float32" begin
#
# @testset for i in 0x00:0xff
# if ~isnan(Float8_4(i))
# @test i == reinterpret(UInt8,Float8_4(Float32(Float8_4(i))))
# end
# end
# end
@testset "Conversion Float8_4 <-> Float32" begin

@testset for i in 0x00:0xff
if !isnan(Float8_4(i))
@test i == reinterpret(UInt8,Float8_4(Float32(Float8_4(i))))
end
end
end

@testset "Negation" begin

@testset for i in 0x00:0xff
f8 = Float8(i)
f8_4 = Float8_4(i)

if ~isnan(f8)
if !isnan(f8)
@test f8 == -(-f8)
end

if ~isnan(f8_4)
if !isnan(f8_4)
@test f8_4 == -(-f8_4)
end
end
Expand All @@ -107,12 +106,12 @@ end
f8 = Float8(i)
f8_4 = Float8_4(i)

if ~isnan(f8)
if !isnan(f8)
@test f8 >= floor(f8)
@test f8 <= ceil(f8)
end

if ~isnan(f8_4)
if !isnan(f8_4)
@test f8_4 >= floor(f8_4)
@test f8_4 <= ceil(f8_4)
end
Expand All @@ -127,7 +126,7 @@ end
f1 = Float8(i)
f2 = Float8(j)

if ~isnan(f1) && ~isnan(f2) && isfinite(f1) && isfinite(f2)
if !isnan(f1) && !isnan(f2) && isfinite(f1) && isfinite(f2)
@test abs(f1) + abs(f2) >= abs(f1+f2)
@test abs(f1) - abs(f2) <= abs(f1-f2)
@test abs(f1) * abs(f2) >= f1*f2
Expand All @@ -144,7 +143,7 @@ end
f1 = Float8_4(i)
f2 = Float8_4(j)

if ~isnan(f1) && ~isnan(f2) && isfinite(f1) && isfinite(f2)
if !isnan(f1) && !isnan(f2) && isfinite(f1) && isfinite(f2)
@test abs(f1) + abs(f2) >= abs(f1+f2)
@test abs(f1) - abs(f2) <= abs(f1-f2)
@test abs(f1) * abs(f2) >= f1*f2
Expand Down
Loading