Skip to content

Commit

Permalink
Merge pull request #100 from dpsanders/refactor_files
Browse files Browse the repository at this point in the history
Refactor files to remove small files and simplify file names
  • Loading branch information
dpsanders committed Apr 7, 2016
2 parents bafad67 + 9bf2e71 commit d1905e8
Show file tree
Hide file tree
Showing 28 changed files with 151 additions and 219 deletions.
File renamed without changes.
File renamed without changes.
52 changes: 41 additions & 11 deletions src/intervals/intervals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,46 @@ eltype{T<:Real}(x::Interval{T}) = T


## Include files
include("special_intervals.jl")
include("printing.jl")
include("rationalize.jl")
include("parameters.jl")
include("rounding.jl")
include("macro_definitions.jl")
include("conversion_promotion.jl")
include("arithmetic.jl")
include("special.jl")
include("macros.jl")
include("conversion.jl")
include("precision.jl")
include("arithmetic.jl")
include("functions.jl")
include("trigonometric_functions.jl")
include("hyperbolic_functions.jl")
include("syntax.jl")
include("trigonometric.jl")
include("hyperbolic.jl")


# Syntax for intervals

a..b = @interval(a, b)

macro I_str(ex) # I"[3,4]"
@interval(ex)
end


## Output

function basic_show(io::IO, a::Interval)
if isempty(a)
output = ""
else
output = "[$(a.lo), $(a.hi)]"
output = replace(output, "inf", "")
output = replace(output, "Inf", "")

output
end

print(io, output)
end

show(io::IO, a::Interval) = basic_show(io, a)
show(io::IO, a::Interval{BigFloat}) = ( basic_show(io, a); print(io, subscriptify(precision(a.lo))) )

function subscriptify(n::Int)
subscript_digits = [c for c in "₀₁₂₃₄₅₆₇₈₉"]
dig = reverse(digits(n))
join([subscript_digits[i+1] for i in dig])
end
31 changes: 0 additions & 31 deletions src/intervals/macro_definitions.jl

This file was deleted.

70 changes: 22 additions & 48 deletions src/intervals/rounding.jl → src/intervals/macros.jl
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
# This file is part of the ValidatedNumerics.jl package; MIT licensed

# Rounding for rational intervals, e.g for sqrt of rational interval:
# Find the corresponding AbstractFloat type for a given rational type
doc"""The `@interval` macro is the main method to create an interval.
It converts each expression into a narrow interval that is guaranteed to contain the true value passed by the user in the one or two expressions passed to it.
When passed two expressions, it takes the hull of the resulting intervals
to give a guaranteed containing interval.
Base.float{T}(::Type{Rational{T}}) = typeof(float(one(Rational{T})))
Examples:
```
@interval(0.1)
# better to just do the following ?
# Base.float(::Type{Rational{Int64}}) = Float64
# Base.float(::Type{Rational{BigInt}}) = BigFloat
@interval(0.1, 0.2)
# Use that type for rounding with rationals, e.g. for sqrt:
@interval(1/3, 1/6)
if VERSION < v"0.5.0-dev+1182"
@interval(1/3^2)
```
"""
macro interval(expr1, expr2...)
make_interval(:(parameters.precision_type), expr1, expr2)
end

function Base.with_rounding{T}(f::Function, ::Type{Rational{T}},
rounding_mode::RoundingMode)
setrounding(f, float(Rational{T}), rounding_mode)
end
doc"The `@floatinterval` macro constructs an interval with `Float64` entries."
macro floatinterval(expr1, expr2...)
make_interval(Float64, expr1, expr2)
end

else
function Base.setrounding{T}(f::Function, ::Type{Rational{T}},
rounding_mode::RoundingMode)
setrounding(f, float(Rational{T}), rounding_mode)
end
doc"The `@biginterval` macro constructs an interval with `BigFloat` entries."
macro biginterval(expr1, expr2...)
make_interval(BigFloat, expr1, expr2)
end


Expand Down Expand Up @@ -67,7 +72,6 @@ end




doc"""`transform` transforms a string by applying the function `f` and type
`T` to each argument, i.e. `:(x+y)` is transformed to `:(f(T, x) + f(T, y))`
"""
Expand Down Expand Up @@ -124,33 +128,3 @@ function make_interval(T, expr1, expr2)

:(hull($expr1, $expr2))
end


float(x::Interval) =
# @round(BigFloat, convert(Float64, x.lo), convert(Float64, x.hi))
convert(Interval{Float64}, x)

## Change type of interval rounding:


doc"""`get_interval_rounding()` returns the current interval rounding mode.
There are two possible rounding modes:
- :narrow -- changes the floating-point rounding mode to `RoundUp` and `RoundDown`.
This gives the narrowest possible interval.
- :wide -- Leaves the floating-point rounding mode in `RoundNearest` and uses
`prevfloat` and `nextfloat` to achieve directed rounding. This creates an interval of width 2`eps`.
"""

get_interval_rounding() = parameters.rounding

function set_interval_rounding(mode)
if mode [:wide, :narrow]
throw(ArgumentError("Only possible interval rounding modes are `:wide` and `:narrow`"))
end

parameters.rounding = mode # a symbol
end

big{T}(x::Interval{T}) = convert(Interval{BigFloat}, x)
14 changes: 0 additions & 14 deletions src/intervals/parameters.jl

This file was deleted.

72 changes: 72 additions & 0 deletions src/intervals/precision.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# This file is part of the ValidatedNumerics.jl package; MIT licensed

type IntervalParameters

precision_type::Type
precision::Int
rounding::Symbol
pi::Interval{BigFloat}

IntervalParameters() = new(BigFloat, 256, :narrow) # leave out pi
end

const parameters = IntervalParameters()


## Precision:

doc"`big53` creates an equivalent `BigFloat` interval to a given `Float64` interval."
Expand Down Expand Up @@ -47,3 +60,62 @@ const float_interval_pi = convert(Interval{Float64}, pi) # does not change

pi_interval(::Type{BigFloat}) = parameters.pi
pi_interval(::Type{Float64}) = float_interval_pi


# Rounding for rational intervals, e.g for sqrt of rational interval:
# Find the corresponding AbstractFloat type for a given rational type

Base.float{T}(::Type{Rational{T}}) = typeof(float(one(Rational{T})))

# better to just do the following ?
# Base.float(::Type{Rational{Int64}}) = Float64
# Base.float(::Type{Rational{BigInt}}) = BigFloat

# Use that type for rounding with rationals, e.g. for sqrt:

if VERSION < v"0.5.0-dev+1182"

function Base.with_rounding{T}(f::Function, ::Type{Rational{T}},
rounding_mode::RoundingMode)
setrounding(f, float(Rational{T}), rounding_mode)
end

else
function Base.setrounding{T}(f::Function, ::Type{Rational{T}},
rounding_mode::RoundingMode)
setrounding(f, float(Rational{T}), rounding_mode)
end
end





float(x::Interval) =
# @round(BigFloat, convert(Float64, x.lo), convert(Float64, x.hi))
convert(Interval{Float64}, x)

## Change type of interval rounding:


doc"""`get_interval_rounding()` returns the current interval rounding mode.
There are two possible rounding modes:
- :narrow -- changes the floating-point rounding mode to `RoundUp` and `RoundDown`.
This gives the narrowest possible interval.
- :wide -- Leaves the floating-point rounding mode in `RoundNearest` and uses
`prevfloat` and `nextfloat` to achieve directed rounding. This creates an interval of width 2`eps`.
"""

get_interval_rounding() = parameters.rounding

function set_interval_rounding(mode)
if mode [:wide, :narrow]
throw(ArgumentError("Only possible interval rounding modes are `:wide` and `:narrow`"))
end

parameters.rounding = mode # a symbol
end

big{T}(x::Interval{T}) = convert(Interval{BigFloat}, x)
26 changes: 0 additions & 26 deletions src/intervals/printing.jl

This file was deleted.

53 changes: 0 additions & 53 deletions src/intervals/rationalize.jl

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is part of the ValidatedNumerics.jl package; MIT licensed

## Definitions of special intervals
## Definitions of special intervals and associated functions

## Empty interval:
doc"""`emptyinterval`s are represented as the interval [∞, -∞]; note
Expand Down
7 changes: 0 additions & 7 deletions src/intervals/syntax.jl

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 0 additions & 10 deletions test/interval_tests/interval_tests.jl

This file was deleted.

10 changes: 10 additions & 0 deletions test/interval_tests/intervals.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file is part of the ValidatedNumerics.jl package; MIT licensed

include("construction.jl")
include("consistency.jl")
include("numeric.jl")
include("trig.jl")
include("hyperbolic.jl")
include("non_BigFloat.jl")
include("linear_algebra.jl")
include("loops.jl")
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit d1905e8

Please sign in to comment.