Skip to content
Merged
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
12 changes: 12 additions & 0 deletions test/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,18 @@ function test_clamp_nan(TX::Type)
end
end

function test_sign_related(TX::Type)
for X in target(TX, :i8; ex = :thin)
# `FixedPoint` is not a signed or unsigned integer type
@test_throws Exception signed(X)
@test_throws Exception signed(X(0.5))
@test_throws Exception unsigned(X)
@test_throws Exception unsigned(X(0.5))

@test signbit(X(0.5)) === signbit(X(0.0)) === false
end
end

function test_isinteger(TX::Type)
@testset "isinteger(::$X)" for X in target(TX, :i8, :i16)
xs = typemin(X):eps(X):typemax(X)
Expand Down
10 changes: 4 additions & 6 deletions test/fixed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -614,19 +614,17 @@ end
end

@testset "sign-related functions" begin
@test_throws Exception signed(Q0f7)
@test_throws Exception signed(0.5Q0f7)
@test_throws Exception unsigned(Q0f7)
@test_throws Exception unsigned(0.5Q0f7)
test_sign_related(Fixed)

@test copysign(0.5Q0f7, 0x1) === 0.5Q0f7
@test copysign(0.5Q0f7, -1) === -0.5Q0f7
@test flipsign(0.5Q0f7, 0x1) === 0.5Q0f7
@test flipsign(0.5Q0f7, -1) === -0.5Q0f7
@test_throws ArgumentError sign(0Q0f7)
@test_broken sign(0Q0f7) === zero(Q0f7)
@test_throws ArgumentError sign(0.5Q0f7)
@test sign(0Q1f6) === 0Q1f6
@test sign(0.5Q1f6) === 1Q1f6
@test sign(-0.5Q1f6) === -1Q1f6
@test signbit(0.5Q0f7) === false
@test signbit(-0.5Q0f7) === true
end

Expand Down
10 changes: 4 additions & 6 deletions test/normed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -596,16 +596,14 @@ end
end

@testset "sign-related functions" begin
@test_throws Exception signed(N0f8)
@test_throws Exception signed(1N0f8)
@test_throws Exception unsigned(N0f8)
@test_throws Exception unsigned(1N0f8)
test_sign_related(Normed)

@test_throws ArgumentError copysign(1N0f8, 0x1)
@test_throws ArgumentError copysign(1N0f8, -1)
@test_throws ArgumentError flipsign(1N0f8, 0x1)
@test_throws ArgumentError flipsign(1N0f8, -1)
@test_throws ArgumentError sign(0N0f8)
@test signbit(1N0f8) === false
@test_broken sign(0N0f8) === zero(N0f8)
@test_broken sign(0.5N0f8) === oneunit(N0f8)
end

@testset "bitwise" begin
Expand Down
Loading