Skip to content

Commit cf410dc

Browse files
authored
Add more trunc BigFloat tests (#36027)
* Add more trunc BigFloat tests Taken from #21970 * Use testset instead of eval
1 parent 3222aba commit cf410dc

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

test/mpfr.jl

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,45 @@ end
857857
# Issue #33676
858858
@test trunc(UInt8, parse(BigFloat,"255.1")) == UInt8(255)
859859
@test_throws InexactError trunc(UInt8, parse(BigFloat,"256.1"))
860+
861+
@testset "inexact limits ($T)" for T in Base.BitInteger_types
862+
typemin_and_half = BigFloat(typemin(T)) - 0.5
863+
typemax_and_half = BigFloat(typemax(T)) + 0.5
864+
typemin_and_one = BigFloat(typemin(T)) - 1
865+
typemax_and_one = BigFloat(typemax(T)) + 1
866+
867+
@test trunc(T, typemin_and_half) == typemin(T)
868+
@test trunc(T, typemax_and_half) == typemax(T)
869+
@test_throws InexactError trunc(T, typemin_and_one)
870+
@test_throws InexactError trunc(T, typemax_and_one)
871+
872+
@test_throws InexactError floor(T, typemin_and_half)
873+
@test floor(T, typemax_and_half) == typemax(T)
874+
@test_throws InexactError floor(T, typemin_and_one)
875+
@test_throws InexactError floor(T, typemax_and_one)
876+
877+
@test ceil(T, typemin_and_half) == typemin(T)
878+
@test_throws InexactError ceil(T, typemax_and_half)
879+
@test_throws InexactError ceil(T, typemin_and_one)
880+
@test_throws InexactError ceil(T, typemax_and_one)
881+
882+
if iseven(typemin(T))
883+
@test round(T, typemin_and_half) == typemin(T)
884+
else
885+
@test_throws InexactError round(T, typemin_and_half)
886+
end
887+
888+
if iseven(typemax(T))
889+
@test round(T, typemax_and_half) == typemax(T)
890+
else
891+
@test_throws InexactError round(T, typemax_and_half)
892+
end
893+
894+
@test round(T, BigFloat(typemin(T)) - 0.4) == typemin(T)
895+
@test round(T, BigFloat(typemax(T)) + 0.4) == typemax(T)
896+
@test_throws InexactError round(T, typemin_and_one)
897+
@test_throws InexactError round(T, typemax_and_one)
898+
end
860899
end
861900
@testset "div" begin
862901
@test div(big"1.0",big"0.1") == 9

0 commit comments

Comments
 (0)