Skip to content

Commit

Permalink
Merge pull request #563 from OlivierHnt/1.0-dev-display
Browse files Browse the repository at this point in the history
1.0-dev: Remove `@format`
  • Loading branch information
Kolaru authored Jun 26, 2023
2 parents 7bfad94 + 38d0c8e commit 73e0c41
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 78 deletions.
2 changes: 1 addition & 1 deletion src/IntervalArithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export
PointwisePolicy,
cancelminus, cancelplus, isbounded, isunbounded,
pow, extended_div, nthroot,
setformat, @format
setformat

if VERSION >= v"1.5.0-DEV.124"
import Base: isdisjoint
Expand Down
68 changes: 4 additions & 64 deletions src/display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,18 @@ are reset to the default display options.
Possible options:
- `format` can be:
- `:standard`: `[1, 2]`
- `:midpoint`: display `x::Interval` in the form "mid(x) ± radius(x)"
- `:standard`: `[1, 2]`.
- `:midpoint`: display `x::Interval` in the form "mid(x) ± radius(x)".
- `:full`: display the entire bounds regardless of `sigdigits`.
- `sigdigits`: number (greater or equal to 1) of significant digits to display.
- `decorations`: display the decorations or not.
See also: `@format`.
# Example
```
julia> x = interval(0.1, 0.3) # Default display options
[0.0999999, 0.300001]
julia> setformat(:full) # Equivalent to `@format full`
julia> setformat(:full)
Display parameters:
- format: full
- decorations: true
Expand All @@ -52,7 +50,7 @@ Display parameters:
julia> x
Interval(0.09999999999999999, 0.30000000000000004)
julia> setformat(:standard; sigdigits = 3) # Equivalent to `@format standard 3`
julia> setformat(:standard; sigdigits = 3)
Display parameters:
- format: standard
- decorations: true
Expand All @@ -76,64 +74,6 @@ function setformat(format::Symbol = display_params.format;
return display_params
end

"""
@format [format::Symbol] [decorations::Bool] [sigdigits::Integer]
Change the format used by `show` to display intervals. These options are passed
to the `setformat` function.
Possible options:
- `format` can be:
- `:standard`: `[1, 2]`
- `:midpoint`: display `x::Interval` in the form "mid(x) ± radius(x)"
- `:full`: display the entire bounds regardless of `sigdigits`.
- `sigdigits`: number (greater or equal to 1) of significant digits to display.
- `decorations`: display the decorations or not.
See also: `setformat`.
# Example
```
julia> x = interval(0.1, 0.3) # Default display options
[0.0999999, 0.300001]
julia> @format full # Equivalent to `setformat(:full)``
Display parameters:
- format: full
- decorations: true
- significant digits: 6
julia> x
Interval(0.09999999999999999, 0.30000000000000004)
julia> @format standard true 3 # Equivalent to `setformat(:standard; decorations = true, sigdigits = 3)`
Display parameters:
- format: standard
- decorations: true
- significant digits: 3
julia> x
[0.0999, 0.301]
```
"""
macro format(expr...)
format = Meta.quot(display_params.format)
decorations = display_params.decorations
sigdigits = display_params.sigdigits
for ex in expr
if isa(ex, Symbol)
format = Meta.quot(ex)
elseif isa(ex, Bool)
decorations = ex
elseif isa(ex, Integer)
sigdigits = ex
else
return :(throw(ArgumentError("Only accept arguments of type `Symbol`, `Bool` or `Int` but received $($ex)")))
end
end
return :(setformat($format; decorations = $decorations, sigdigits = $sigdigits))
end

# Printing mechanism for various types of intervals

show(io::IO, ::MIME"text/plain", a::Union{Interval,Complex{<:Interval},DecoratedInterval,IntervalBox}) =
Expand Down
13 changes: 0 additions & 13 deletions test/display_tests/display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -232,19 +232,6 @@ end

end

@testset "@format tests" begin
x = interval(prevfloat(0.1), nextfloat(0.3))

@format full
@test sprint(show, MIME("text/plain"), x) == "Interval{Float64}(0.09999999999999999, 0.30000000000000004)"

@format standard 3
@test sprint(show, MIME("text/plain"), x) == "[0.0999, 0.301]"

@format standard 10
@test sprint(show, MIME("text/plain"), x) == "[0.09999999999, 0.3000000001]"
end

setprecision(BigFloat, 256)

end

0 comments on commit 73e0c41

Please sign in to comment.