Skip to content

Commit 451c9cf

Browse files
authored
Complex powers (#201)
Version 0.7 and 1.0 compatibility including complex powers
1 parent bb04eb8 commit 451c9cf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+783
-841
lines changed

.travis.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@ os:
1010
- osx
1111

1212
julia:
13-
- 0.6
13+
- 0.7
14+
- 1.0
1415
- nightly
1516

16-
matrix:
17-
allow_failures:
18-
- julia: nightly
17+
#matrix:
18+
# allow_failures:
19+
# - julia: nightly
1920

2021
notifications:
2122
email: false
2223

2324
after_success:
24-
- julia -e 'Pkg.add("Documenter")'
25+
- julia -e 'using Pkg; Pkg.add("Documenter")'
2526
- julia -e 'cd(Pkg.dir("IntervalArithmetic")); include(joinpath("docs", "make.jl"))'
2627
- julia -e 'cd(Pkg.dir("IntervalArithmetic")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder()); Codecov.submit(process_folder())'

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ setdisplay(:full)
146146
- `bisect` function in `ValidatedNumerics.RootFinding` for bisecting `Interval`s and `IntervalBox`es #217
147147

148148
### Other
149-
- Many tests use `Base.Test` instead of `FactCheck` #205
149+
- Many tests use `Test` instead of `FactCheck` #205
150150
- Miscellaneous bugfixes
151151

152152
## v0.6

REQUIRE

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
julia 0.6
2-
CRlibm 0.6
3-
StaticArrays 0.5
4-
FastRounding 0.0.4
5-
AdjacentFloats 0.0.5
6-
RecipesBase
7-
Compat 0.69.0
1+
julia 0.7
2+
CRlibm 0.7
3+
StaticArrays 0.8
4+
FastRounding 0.1.2
5+
SetRounding 0.2
6+
RecipesBase 0.5

appveyor.yml

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
environment:
22
matrix:
3-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
4-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
5-
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
6-
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
7-
8-
# uncomment the following lines to allow failures on nightly julia
9-
# (tests will run but not make your overall status red)
10-
matrix:
11-
allow_failures:
12-
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
13-
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
3+
- julia_version: 0.7
4+
- julia_version: 1
5+
- julia_version: nightly
6+
7+
platform:
8+
- x86 # 32-bit
9+
- x64 # 64-bit
10+
11+
# # Uncomment the following lines to allow failures on nightly julia
12+
# # (tests will run but not make your overall status red)
13+
# matrix:
14+
# allow_failures:
15+
# - julia_version: nightly
1416

1517
branches:
1618
only:
1719
- master
20+
- /release-.*/
1821

1922
notifications:
2023
- provider: Email
@@ -23,24 +26,18 @@ notifications:
2326
on_build_status_changed: false
2427

2528
install:
26-
- ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
27-
# If there's a newer build queued for the same PR, cancel this one
28-
- ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod `
29-
https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | `
30-
Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { `
31-
throw "There are newer queued builds for this pull request, failing early." }
32-
# Download most recent Julia Windows binary
33-
- ps: (new-object net.webclient).DownloadFile(
34-
$env:JULIA_URL,
35-
"C:\projects\julia-binary.exe")
36-
# Run installer silently, output to C:\projects\julia
37-
- C:\projects\julia-binary.exe /S /D=C:\projects\julia
29+
- ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/JuliaCI/Appveyor.jl/version-1/bin/install.ps1"))
3830

3931
build_script:
40-
# Need to convert from shallow to complete for Pkg.clone to work
41-
- IF EXIST .git\shallow (git fetch --unshallow)
42-
- C:\projects\julia\bin\julia -e "versioninfo();
43-
Pkg.clone(pwd(), \"IntervalArithmetic\"); Pkg.build(\"IntervalArithmetic\")"
32+
- echo "%JL_BUILD_SCRIPT%"
33+
- C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%"
4434

4535
test_script:
46-
- C:\projects\julia\bin\julia -e "Pkg.test(\"IntervalArithmetic\")"
36+
- echo "%JL_TEST_SCRIPT%"
37+
- C:\julia\bin\julia -e "%JL_TEST_SCRIPT%"
38+
39+
# # Uncomment to support code coverage upload. Should only be enabled for packages
40+
# # which would have coverage gaps without running on Windows
41+
# on_success:
42+
# - echo "%JL_CODECOV_SCRIPT%"
43+
# - C:\julia\bin\julia -e "%JL_CODECOV_SCRIPT%"

docs/src/usage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ to an `Interval{BigFloat}`, and then use routines from the `MPFR` library
293293

294294
- `^`
295295
- `exp2`, `exp10`
296-
- `atan2`, `atanh`
296+
- `atan`, `atanh`
297297

298298
Note, in particular, that in order to obtain correct rounding for the power function (`^`),
299299
intervals are converted to and from `BigFloat`; this implies a significant slow-down in this case.

src/IntervalArithmetic.jl

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,16 @@ __precompile__(true)
55
module IntervalArithmetic
66

77
import CRlibm
8+
89
using StaticArrays
910
using FastRounding
10-
using AdjacentFloats
11-
using Compat
12-
13-
if VERSION <= v"0.7.0-DEV.2004"
14-
import Base: ×, dot
15-
import Compat.Sys
16-
export
17-
else
18-
using Markdown
19-
import Base:
20-
import LinearAlgebra: ×, dot
21-
end
11+
using SetRounding
12+
13+
using Markdown
14+
15+
using LinearAlgebra
16+
import LinearAlgebra: ×, dot
17+
export ×, dot
2218

2319

2420
import Base:
@@ -27,24 +23,26 @@ import Base:
2723
in, zero, one, eps, typemin, typemax, abs, abs2, real, min, max,
2824
sqrt, exp, log, sin, cos, tan, inv,
2925
exp2, exp10, log2, log10,
30-
asin, acos, atan, atan2,
26+
asin, acos, atan,
3127
sinh, cosh, tanh, asinh, acosh, atanh,
3228
union, intersect, isempty,
3329
convert, promote_rule, eltype, size,
3430
BigFloat, float, widen, big,
35-
, , , eps,
31+
, , , , eps,
3632
floor, ceil, trunc, sign, round,
3733
expm1, log1p,
3834
precision,
3935
isfinite, isnan, isinf, iszero,
40-
show, showall,
36+
show,
4137
isinteger, setdiff,
4238
parse, hash
4339

4440
import Base: # for IntervalBox
4541
broadcast, length,
4642
getindex, setindex,
47-
start, next, done, eltype
43+
iterate, eltype
44+
45+
import .Broadcast: broadcasted
4846

4947
export
5048
AbstractInterval, Interval,
@@ -67,6 +65,13 @@ export
6765
export
6866
setindex # re-export from StaticArrays for IntervalBox
6967

68+
69+
if VERSION < v"1.0-dev"
70+
import Base.showall
71+
end
72+
73+
export showall
74+
7075
import Base: rounding, setrounding, setprecision
7176

7277

src/bisect.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ end
2121
Bisect the `IntervalBox` `X` at position α ∈ [0,1] along its longest side.
2222
"""
2323
function bisect(X::IntervalBox, α=where_bisect)
24-
i = indmax(diam.(X)) # find longest side
24+
i = argmax(diam.(X)) # find longest side
2525

2626
return bisect(X, i, α)
2727
end

src/decorations/functions.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# This file is part of the IntervalArithmetic.jl package; MIT licensed
22

3+
Base.literal_pow(::typeof(^), x::DecoratedInterval{T}, ::Val{p}) where {T,p} = x^p
4+
5+
36
# zero, one
47
zero(a::DecoratedInterval{T}) where T<:Real = DecoratedInterval(zero(T))
58
zero(::Type{DecoratedInterval{T}}) where T<:Real = DecoratedInterval(zero(T))
@@ -255,7 +258,7 @@ following the IEEE-1788 Standard (see Sect. 11.7.1, pp 47).
255258
""" union
256259

257260

258-
## Functions on unrestricted domains; tan and atan2 are treated separately
261+
## Functions on unrestricted domains; tan and atan are treated separately
259262
unrestricted_functions =(
260263
:exp, :exp2, :exp10,
261264
:sin, :cos,
@@ -290,10 +293,10 @@ function decay(a::DECORATION)
290293
ill
291294
end
292295

293-
function atan2(yy::DecoratedInterval{T}, xx::DecoratedInterval{T}) where T
296+
function atan(yy::DecoratedInterval{T}, xx::DecoratedInterval{T}) where T
294297
x = interval_part(xx)
295298
y = interval_part(yy)
296-
r = atan2(y, x)
299+
r = atan(y, x)
297300
d = decoration(r)
298301
d = min(d, decoration(xx), decoration(yy))
299302
# Check cases when decoration is trv and decays (from com or dac)

src/display.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,15 @@ end
109109
function round_string(x::BigFloat, digits::Int, r::RoundingMode)
110110

111111
lng = digits + Int32(8)
112-
@compat buf = Array{UInt8}(undef, lng + 1)
112+
buf = Array{UInt8}(undef, lng + 1)
113113

114114
lng = ccall((:mpfr_snprintf,:libmpfr), Int32,
115115
(Ptr{UInt8}, Culong, Ptr{UInt8}, Int32, Ref{BigFloat}...),
116116
buf, lng + 1, "%.$(digits)R*g", Base.MPFR.to_mpfr(r), x)
117117

118118
repr = unsafe_string(pointer(buf))
119119

120-
@compat repr = replace(repr, "nan" => "NaN")
120+
repr = replace(repr, "nan" => "NaN")
121121

122122
return repr
123123
end
@@ -144,8 +144,8 @@ function basic_representation(a::Interval, format=nothing)
144144
bb = round_string(a.hi, sigfigs, RoundUp)
145145

146146
output = "[$aa, $bb]"
147-
@compat output = replace(output, "inf" => "")
148-
@compat output = replace(output, "Inf" => "")
147+
output = replace(output, "inf" => "")
148+
output = replace(output, "Inf" => "")
149149

150150
elseif format == :full
151151
output = "Interval($(a.lo), $(a.hi))"

src/intervals/complex.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
function ^(x::Complex{Interval{T}}, n::Integer) where {T}
2+
if n < 0
3+
return inv(x)^n
4+
end
5+
6+
return Base.power_by_squaring(x, n)
7+
end
8+
9+
function ^(x::Complex{Interval{T}}, y::Real) where {T}
10+
return exp(y*log(x))
11+
end
12+
13+
function ^(x::Complex{Interval{T}}, y::Complex) where {T}
14+
return exp(y*log(x))
15+
end
16+
17+
118
function ssqs(x::T, y::T,RND::RoundingMode) where T<:AbstractFloat
219
k::Int = 0
320
ρ = +(*(x,x,RND),*(y,y,RND),RND)
@@ -75,3 +92,11 @@ function sqrt(z::Complex{Interval{T}}) where T<:AbstractFloat
7592

7693
Complex(ξ,η)
7794
end
95+
96+
97+
function log(z::Complex{T}) where T<:Interval
98+
ρ = abs(z)
99+
θ = angle(z)
100+
101+
return log(ρ) + im * θ
102+
end

0 commit comments

Comments
 (0)