Skip to content

Commit

Permalink
Fix throw_complex_domainerror error message for log[1p] (#28621)
Browse files Browse the repository at this point in the history
* Fix throw_complex_domainerror error message for log[1p]

This seems pretty clearly unintentional.  Relevant history is in
d4229be and
d555a9a.

* Require `Symbol` as first argument to `throw_complex_domainerror`

(cherry picked from commit a3a2b7a)
  • Loading branch information
garrison authored and KristofferC committed Aug 19, 2018
1 parent 3eb43ed commit 668718c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
20 changes: 10 additions & 10 deletions base/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ using Core.Intrinsics: sqrt_llvm

using .Base: IEEEFloat

@noinline function throw_complex_domainerror(f, x)
@noinline function throw_complex_domainerror(f::Symbol, x)
throw(DomainError(x, string("$f will only return a complex result if called with a ",
"complex argument. Try $f(Complex(x)).")))
end
Expand Down Expand Up @@ -198,17 +198,17 @@ julia> log(4,2)
0.5
julia> log(-2, 3)
ERROR: DomainError with log:
-2.0 will only return a complex result if called with a complex argument. Try -2.0(Complex(x)).
ERROR: DomainError with -2.0:
log will only return a complex result if called with a complex argument. Try log(Complex(x)).
Stacktrace:
[1] throw_complex_domainerror(::Float64, ::Symbol) at ./math.jl:31
[1] throw_complex_domainerror(::Symbol, ::Float64) at ./math.jl:31
[...]
julia> log(2, -3)
ERROR: DomainError with log:
-3.0 will only return a complex result if called with a complex argument. Try -3.0(Complex(x)).
ERROR: DomainError with -3.0:
log will only return a complex result if called with a complex argument. Try log(Complex(x)).
Stacktrace:
[1] throw_complex_domainerror(::Float64, ::Symbol) at ./math.jl:31
[1] throw_complex_domainerror(::Symbol, ::Float64) at ./math.jl:31
[...]
```
Expand Down Expand Up @@ -459,10 +459,10 @@ julia> log1p(0)
0.0
julia> log1p(-2)
ERROR: DomainError with log1p:
-2.0 will only return a complex result if called with a complex argument. Try -2.0(Complex(x)).
ERROR: DomainError with -2.0:
log1p will only return a complex result if called with a complex argument. Try log1p(Complex(x)).
Stacktrace:
[1] throw_complex_domainerror(::Float64, ::Symbol) at ./math.jl:31
[1] throw_complex_domainerror(::Symbol, ::Float64) at ./math.jl:31
[...]
```
"""
Expand Down
8 changes: 4 additions & 4 deletions base/special/log.jl
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ function log(x::Float64)
elseif isnan(x)
NaN
else
throw_complex_domainerror(x, :log)
throw_complex_domainerror(:log, x)
end
end

Expand Down Expand Up @@ -318,7 +318,7 @@ function log(x::Float32)
elseif isnan(x)
NaN32
else
throw_complex_domainerror(x, :log)
throw_complex_domainerror(:log, x)
end
end

Expand Down Expand Up @@ -353,7 +353,7 @@ function log1p(x::Float64)
elseif isnan(x)
NaN
else
throw_complex_domainerror(x, :log1p)
throw_complex_domainerror(:log1p, x)
end
end

Expand Down Expand Up @@ -386,7 +386,7 @@ function log1p(x::Float32)
elseif isnan(x)
NaN32
else
throw_complex_domainerror(x, :log1p)
throw_complex_domainerror(:log1p, x)
end
end

Expand Down

0 comments on commit 668718c

Please sign in to comment.