|
1 | 1 | module FixedPointNumbers
|
2 | 2 |
|
3 | 3 | import Base: ==, <, <=, -, +, *, /, ~, isapprox,
|
4 |
| - convert, promote_rule, show, bitstring, abs, decompose, |
| 4 | + convert, promote_rule, print, show, bitstring, abs, decompose, |
5 | 5 | isnan, isinf, isfinite, isinteger,
|
6 | 6 | zero, oneunit, one, typemin, typemax, floatmin, floatmax, eps, reinterpret,
|
7 | 7 | big, rationalize, float, trunc, round, floor, ceil, bswap, clamp,
|
@@ -468,35 +468,40 @@ end
|
468 | 468 |
|
469 | 469 | function _alias_symbol(::Type{X}) where {X <: FixedPoint}
|
470 | 470 | if @generated
|
471 |
| - sym = string(alias_symbol(X)) |
472 |
| - return :(Symbol($sym)) |
| 471 | + return QuoteNode(alias_symbol(X)) |
473 | 472 | else
|
474 | 473 | return alias_symbol(X)
|
475 | 474 | end
|
476 | 475 | end
|
477 | 476 |
|
| 477 | +function print(io::IO, x::FixedPoint{T,f}) where {T,f} |
| 478 | + compact = get(io, :compact, false)::Bool |
| 479 | + log10_2 = 0.3010299956639812 |
| 480 | + digits = min(ceil(Int, f * log10_2), compact ? 6 : typemax(Int)) |
| 481 | + val = round(convert(Float64, x), digits=digits) |
| 482 | + print(io, val) |
| 483 | +end |
| 484 | + |
478 | 485 | @inline function showtype(io::IO, ::Type{X}) where {X <: FixedPoint}
|
479 | 486 | if hasalias(X)
|
480 | 487 | write(io, _alias_symbol(X))
|
481 | 488 | else
|
482 | 489 | print(io, X)
|
483 | 490 | end
|
484 |
| - io |
| 491 | + return nothing |
485 | 492 | end
|
486 | 493 |
|
487 | 494 | function show(io::IO, x::FixedPoint{T,f}) where {T,f}
|
488 | 495 | compact = get(io, :compact, false)::Bool
|
489 |
| - log10_2 = 0.3010299956639812 |
490 |
| - digits = min(ceil(Int, f * log10_2), compact ? 6 : typemax(Int)) |
491 |
| - val = round(convert(Float64, x), digits=digits) |
492 | 496 | if compact || get(io, :typeinfo, Any) === typeof(x)
|
493 |
| - show(io, val) |
| 497 | + print(io, x) |
494 | 498 | elseif hasalias(typeof(x))
|
495 |
| - show(io, val) |
| 499 | + print(io, x) |
496 | 500 | showtype(io, typeof(x))
|
497 | 501 | else
|
498 |
| - print(io, typeof(x), '(', val, ')') |
| 502 | + print(io, typeof(x), '(', x, ')') |
499 | 503 | end
|
| 504 | + return nothing |
500 | 505 | end
|
501 | 506 |
|
502 | 507 | if VERSION < v"1.6.0-DEV.356" # JuliaLang/julia#36107
|
|
0 commit comments