|
857 | 857 | # Issue #33676
|
858 | 858 | @test trunc(UInt8, parse(BigFloat,"255.1")) == UInt8(255)
|
859 | 859 | @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 |
860 | 899 | end
|
861 | 900 | @testset "div" begin
|
862 | 901 | @test div(big"1.0",big"0.1") == 9
|
|
0 commit comments