Skip to content

Commit

Permalink
update message for DomainError
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Sep 18, 2013
1 parent fb18349 commit dfea709
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
21 changes: 10 additions & 11 deletions base/repl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,19 @@ function showerror(io::IO, e::LoadError, bt)
end

function showerror(io::IO, e::DomainError, bt)
try
print(io, "DomainError")
for b in bt
code = ccall(:jl_lookup_code_address, Any, (Ptr{Void}, Int32), b, 0)
if length(code) == 3
if code[1] in (:log, :log2, :log10, :sqrt) # TODO add :besselj, :besseli, :bessely, :besselk
print(io, "\n ", code[1]," will only return complex result if called width a complex argument. Eg: ", code[1], "(complex(x))")
end
break
print(io, "DomainError")
for b in bt
code = ccall(:jl_lookup_code_address, Any, (Ptr{Void}, Int32), b, 0)
if length(code) == 3
if code[1] in (:log, :log2, :log10, :sqrt) # TODO add :besselj, :besseli, :bessely, :besselk
print(io, "\n", code[1],
" will only return a complex result if called width a complex argument.",
"\ntry ", code[1], "(complex(x))")
end
break
end
finally
show_backtrace(io, bt)
end
show_backtrace(io, bt)
end

showerror(io::IO, e::SystemError) = print(io, "$(e.prefix): $(strerror(e.errnum))")
Expand Down
6 changes: 3 additions & 3 deletions doc/stdlib/base.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2345,7 +2345,7 @@ Mathematical Functions

.. function:: log(x)

Compute the natural logarithm of ``x``. Throws ``DomainError`` for negative ``Real`` arguments. Use ``Complex`` negative arguments instead.
Compute the natural logarithm of ``x``. Throws ``DomainError`` for negative ``Real`` arguments. Use complex negative arguments instead.

.. function:: log2(x)

Expand All @@ -2357,7 +2357,7 @@ Mathematical Functions

.. function:: log1p(x)

Accurate natural logarithm of ``1+x``. Throws ``DomainError`` for negative ``Real`` arguments.
Accurate natural logarithm of ``1+x``. Throws ``DomainError`` for ``Real`` arguments less than -1.

.. function:: frexp(val, exp)

Expand Down Expand Up @@ -2463,7 +2463,7 @@ Mathematical Functions

.. function:: sqrt(x)

Return :math:`\sqrt{x}`. Throws ``DomainError`` for negative ``Real`` arguments. Use ``Complex`` negative arguments instead.
Return :math:`\sqrt{x}`. Throws ``DomainError`` for negative ``Real`` arguments. Use complex negative arguments instead.

.. function:: isqrt(x)

Expand Down

0 comments on commit dfea709

Please sign in to comment.