Skip to content

Commit cc7f9aa

Browse files
authored
simplify Amos exception (#46)
1 parent aba8c8a commit cc7f9aa

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed

src/bessel.jl

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,26 @@ using Base.Math: nan_dom_err
44

55
struct AmosException <: Exception
66
id::Int32
7-
msg::String
8-
9-
function AmosException(id::Integer)
10-
msg = if id == 0
11-
"Normal return, computation complete."
12-
elseif id == 1
13-
"Input error"
14-
elseif id == 2
15-
"Overflow"
16-
elseif id == 3
17-
"Input argument magnitude large, less than half machine accuracy loss by argument reduction."
18-
elseif id == 4
19-
"Input argument magnitude too large, complete loss of accuracy by argument reduction."
20-
elseif id == 5
21-
"Algorithm termination condition not met."
22-
else
23-
throw(ArgumentError("invalid AMOS error flag: $id"))
24-
end
25-
new(id,msg)
7+
end
8+
9+
function Base.showerror(io::IO, ex::AmosException)
10+
print(io, "AmosException with id $(ex.id): ")
11+
if ex.id == 0
12+
print(io, "normal return, computation complete.")
13+
elseif ex.id == 1
14+
print(io, "input error.")
15+
elseif ex.id == 2
16+
print(io, "overflow.")
17+
elseif ex.id == 3
18+
print(io, "input argument magnitude large, less than half machine accuracy loss by argument reduction.")
19+
elseif ex.id == 4
20+
print(io, "input argument magnitude too large, complete loss of accuracy by argument reduction.")
21+
elseif ex.id == 5
22+
print(io, "algorithm termination condition not met.")
23+
else
24+
print(io, "invalid error flag.")
2625
end
2726
end
28-
Base.showerror(io::IO, err::AmosException) = print(io, "AmosException with id $(err.id): $(err.msg)")
2927

3028
## Airy functions
3129
function _airy(z::Complex128, id::Int32, kode::Int32)

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,4 +544,4 @@ end
544544
@test typeof(SF.zeta(complex(1), 2.0)) == Complex{Float64}
545545
end
546546

547-
@test sprint(showerror, SF.AmosException(1)) == "AmosException with id 1: Input error"
547+
@test sprint(showerror, SF.AmosException(1)) == "AmosException with id 1: input error."

0 commit comments

Comments
 (0)