@@ -19,36 +19,6 @@ using Test
19
19
@test a - b === - c
20
20
@test b - a === c
21
21
end
22
- @testset " RoundToZero" begin
23
- setrounding (Float64,RoundToZero) do
24
- @test a + b === d
25
- @test - a - b === - d
26
- @test a - b === - c
27
- @test b - a === c
28
- end
29
- # Sanity check to see if we have returned to RoundNearest
30
- @test a + b === 1.
31
- @test - a - b === - 1.
32
- @test a - b == - c
33
- @test b - a == c
34
- end
35
-
36
- @testset " RoundUp" begin
37
- setrounding (Float64,RoundUp) do
38
- @test a + b === 1.
39
- @test - a - b === - d
40
- @test a - b === - c
41
- @test b - a === c
42
- end
43
- end
44
- @testset " RoundDown" begin
45
- setrounding (Float64,RoundDown) do
46
- @test a + b === d
47
- @test - a - b === - 1.
48
- @test a - b === - c
49
- @test b - a === c
50
- end
51
- end
52
22
end
53
23
54
24
@testset " Float32 checks" begin
63
33
@test a32 - b32 === - c32
64
34
@test b32 - a32 === c32
65
35
end
66
- @testset " RoundToZero" begin
67
- setrounding (Float32,RoundToZero) do
68
- @test a32 + b32 === d32
69
- @test - a32 - b32 === - d32
70
- @test a32 - b32 === - c32
71
- @test b32 - a32 === c32
72
- end
73
-
74
- # Sanity check to see if we have returned to RoundNearest
75
- @test a32 + b32 === 1.0f0
76
- @test - a32 - b32 === - 1.0f0
77
- @test a32 - b32 == - c32
78
- @test b32 - a32 == c32
79
- end
80
- @testset " RoundUp" begin
81
- setrounding (Float32,RoundUp) do
82
- @test a32 + b32 === 1.0f0
83
- @test - a32 - b32 === - d32
84
- @test a32 - b32 === - c32
85
- @test b32 - a32 === c32
86
- end
87
- end
88
- @testset " RoundDown" begin
89
- setrounding (Float32,RoundDown) do
90
- @test a32 + b32 === d32
91
- @test - a32 - b32 === - 1.0f0
92
- @test a32 - b32 === - c32
93
- @test b32 - a32 === c32
94
- end
95
- end
96
36
end
97
37
98
38
@testset " convert with rounding" begin
99
39
for v = [sqrt (2 ),- 1 / 3 ,nextfloat (1.0 ),prevfloat (1.0 ),nextfloat (- 1.0 ),
100
40
prevfloat (- 1.0 ),nextfloat (0.0 ),prevfloat (0.0 )]
41
+
101
42
pn = Float32 (v,RoundNearest)
102
43
@test pn == convert (Float32,v)
44
+
103
45
pz = Float32 (v,RoundToZero)
104
- @test pz == setrounding (()-> convert (Float32,v), Float64, RoundToZero)
46
+ @test abs (pz) <= abs (v) < nextfloat (abs (pz))
47
+ @test signbit (pz) == signbit (v)
48
+
105
49
pd = Float32 (v,RoundDown)
106
- @test pd == setrounding (()-> convert (Float32,v), Float64, RoundDown)
50
+ @test pd <= v < nextfloat (pd)
51
+
107
52
pu = Float32 (v,RoundUp)
108
- @test pu == setrounding (() -> convert (Float32,v), Float64, RoundUp)
53
+ @test prevfloat (pu) < v <= pu
109
54
110
55
@test pn == pd || pn == pu
111
56
@test v > 0 ? pz == pd : pz == pu
0 commit comments