Skip to content

Commit

Permalink
Add test for undefined behavior of unsafe_trunc
Browse files Browse the repository at this point in the history
  • Loading branch information
kimikage committed Apr 27, 2024
1 parent 37e83e7 commit 26df4bf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/fixed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,22 @@ end

@test -1 % Q0f7 === Q0f7(-1)
@test -2 % Q0f7 === Q0f7(0)

# issue #288
_fixed(::Val, x) = x % Q0f7
_fixed(::Val{16}, x) = x % Q0f15
buf = IOBuffer()
for v in (8, 16)
show(buf, _fixed(Val(v), 1.0))
print(buf, " ")
end
str = String(take!(buf))
if str == "-1.0Q0f7 -1.0Q0f15 " # just leave it in the report
@test str == "-1.0Q0f7 -1.0Q0f15 "
else
@test_broken str == "-1.0Q0f7 -1.0Q0f15 "
@warn "broken result: " * repr(str)
end
end

@testset "neg" begin
Expand Down
16 changes: 16 additions & 0 deletions test/normed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,22 @@ end
# issue #211
@test big"1.2" % N0f8 === 0.196N0f8
@test reinterpret(BigFloat(0x0_01234567_89abcdef) % N63f1) === 0x01234567_89abcdef

# issue #288
_normed(::Val, x) = x % N0f8
_normed(::Val{16}, x) = x % N0f16
buf = IOBuffer()
for v in (8, 16)
show(buf, _normed(Val(v), 1.0))
print(buf, " ")
end
str = String(take!(buf))
if str == "1.0N0f8 1.0N0f16 " # just leave it in the report
@test str == "1.0N0f8 1.0N0f16 "
else
@test_broken str == "1.0N0f8 1.0N0f16 "
@warn "broken result: " * repr(str)
end
end

@testset "arithmetic" begin
Expand Down

0 comments on commit 26df4bf

Please sign in to comment.