|
64 | 64 | @test_throws DomainError zero(Fixed{Int16,17}) |
65 | 65 | end |
66 | 66 |
|
| 67 | +@testset "construction using type suffix" begin |
| 68 | + @test 0.635Q0f7 === Q0f7(0.635) |
| 69 | + @test 0.635Q5f10 === Q5f10(0.635) |
| 70 | + @test 0.635Q3f12 === Q3f12(0.635) |
| 71 | + @test 0.635Q1f14 === Q1f14(0.635) |
| 72 | + @test 0.635Q0f15 === Q0f15(0.635) |
| 73 | + |
| 74 | + @test_throws ArgumentError 1.1Q0f7 |
| 75 | + |
| 76 | + @test wrapping_mul(0.635, Q0f7) === Q0f7(0.635) |
| 77 | + @test wrapping_mul(1.635, Q0f7) === Q0f7(-0.365) |
| 78 | + @test saturating_mul(0.635, Q0f7) === Q0f7(0.635) |
| 79 | + @test saturating_mul(1.635, Q0f7) === Q0f7(0.992) |
| 80 | + @test checked_mul(0.635, Q0f7) === Q0f7(0.635) |
| 81 | + @test_throws ArgumentError checked_mul(1.635, Q0f7) |
| 82 | +end |
| 83 | + |
67 | 84 | @testset "reinterpret/bitstring" begin |
68 | 85 | @test reinterpret(Q0f7, signed(0xa2)) === -0.734375Q0f7 |
69 | 86 | @test reinterpret(Q5f10, signed(0x00a2)) === 0.158203125Q5f10 |
|
275 | 292 | xs = typemin(F):eps(F):typemax(F) |
276 | 293 | fneg(x) = -float(x) |
277 | 294 | @test all(x -> wrapping_neg(wrapping_neg(x)) === x, xs) |
278 | | - @test all(x -> saturating_neg(x) == clamp(fneg(x), F), xs) |
| 295 | + @test all(x -> saturating_neg(x) === clamp(fneg(x), F), xs) |
279 | 296 | @test all(x -> !(typemin(F) < fneg(x) < typemax(F)) || |
280 | 297 | wrapping_neg(x) === checked_neg(x) === fneg(x) % F, xs) |
281 | 298 | end |
|
301 | 318 | xys = ((x, y) for x in xs, y in xs) |
302 | 319 | fadd(x, y) = float(x) + float(y) |
303 | 320 | @test all(((x, y),) -> wrapping_sub(wrapping_add(x, y), y) === x, xys) |
304 | | - @test all(((x, y),) -> saturating_add(x, y) == clamp(fadd(x, y), F), xys) |
| 321 | + @test all(((x, y),) -> saturating_add(x, y) === clamp(fadd(x, y), F), xys) |
305 | 322 | @test all(((x, y),) -> !(typemin(F) < fadd(x, y) < typemax(F)) || |
306 | 323 | wrapping_add(x, y) === checked_add(x, y) === fadd(x, y) % F, xys) |
307 | 324 | end |
|
326 | 343 | xys = ((x, y) for x in xs, y in xs) |
327 | 344 | fsub(x, y) = float(x) - float(y) |
328 | 345 | @test all(((x, y),) -> wrapping_add(wrapping_sub(x, y), y) === x, xys) |
329 | | - @test all(((x, y),) -> saturating_sub(x, y) == clamp(fsub(x, y), F), xys) |
| 346 | + @test all(((x, y),) -> saturating_sub(x, y) === clamp(fsub(x, y), F), xys) |
330 | 347 | @test all(((x, y),) -> !(typemin(F) < fsub(x, y) < typemax(F)) || |
331 | 348 | wrapping_sub(x, y) === checked_sub(x, y) === fsub(x, y) % F, xys) |
332 | 349 | end |
|
0 commit comments