|
404 | 404 | end
|
405 | 405 | end
|
406 | 406 | end
|
| 407 | + |
| 408 | + @testset "limits" begin |
| 409 | + for T in CONTAINER_TYPES |
| 410 | + f = FixedPointDecimals.max_exp10(T) + 1 |
| 411 | + @eval begin |
| 412 | + powt = FixedPointDecimals.coefficient(FD{$T,$f}) |
| 413 | + |
| 414 | + # ideally we would just use `typemax(T)` but due to precision issues with |
| 415 | + # floating-point its possible the closest float will exceed `typemax(T)`. |
| 416 | + max_int = trunc(BigInt, prevfloat(typemax($T) / powt) * powt) |
| 417 | + min_int = trunc(BigInt, nextfloat(typemin($T) / powt) * powt) |
| 418 | + |
| 419 | + # Do not need to know the exact value as we're primarily looking for |
| 420 | + # issues relating to overflow |
| 421 | + @test trunc(FD{$T,$f}, max_int / powt).i in (max_int, max_int - 1) |
| 422 | + @test trunc(FD{$T,$f}, min_int / powt).i in (min_int, min_int + 1) |
| 423 | + end |
| 424 | + end |
| 425 | + end |
407 | 426 | end
|
408 | 427 |
|
409 | 428 | # eps that works for integers too
|
@@ -448,6 +467,30 @@ epsi{T}(::Type{T}) = eps(T)
|
448 | 467 | @test floor(FD3, x) == floor(FD4, x) == FD4(x)
|
449 | 468 | end
|
450 | 469 | end
|
| 470 | + |
| 471 | + @testset "limits" begin |
| 472 | + for T in CONTAINER_TYPES |
| 473 | + f = FixedPointDecimals.max_exp10(T) + 1 |
| 474 | + @eval begin |
| 475 | + powt = FixedPointDecimals.coefficient(FD{$T,$f}) |
| 476 | + |
| 477 | + # ideally we would just use `typemax(T)` but due to precision issues with |
| 478 | + # floating-point its possible the closest float will exceed `typemax(T)`. |
| 479 | + # Using BigInt as this will avoid overflowing when we do `max_int + 1` and |
| 480 | + # `min_int - 1`. |
| 481 | + max_int = trunc(BigInt, prevfloat(typemax($T) / powt) * powt) |
| 482 | + min_int = trunc(BigInt, nextfloat(typemin($T) / powt) * powt) |
| 483 | + |
| 484 | + # Do not need to know the exact value as we're primarily looking for |
| 485 | + # issues relating to overflow |
| 486 | + @test floor(FD{$T,$f}, max_int / powt).i in (max_int, max_int - 1) |
| 487 | + @test floor(FD{$T,$f}, min_int / powt).i in (min_int, min_int - 1) |
| 488 | + |
| 489 | + @test ceil(FD{$T,$f}, max_int / powt).i in (max_int, max_int + 1) |
| 490 | + @test ceil(FD{$T,$f}, min_int / powt).i in (min_int, min_int + 1) |
| 491 | + end |
| 492 | + end |
| 493 | + end |
451 | 494 | end
|
452 | 495 |
|
453 | 496 | @testset "print" begin
|
|
0 commit comments