Skip to content

Commit 201c916

Browse files
timholyivarne
authored andcommitted
Raise informative error for exponentiation to negative power (see #3024)
(cherry picked from commit 79c9dfc) make #8784 work on Mac (cherry picked from commit d2252d0)
1 parent f218d2e commit 201c916

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

base/replutil.jl

+4
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ function showerror(io::IO, e::DomainError, bt)
9090
print(io, "\n", code[1],
9191
" will only return a complex result if called with a complex argument.",
9292
"\ntry ", code[1], "(complex(x))")
93+
elseif (code[1] == :^ && code[2] == symbol("intfuncs.jl")) ||
94+
code[1] == :power_by_squaring
95+
print(io, "\nCannot raise an integer x to a negative power -n. Make x a float by adding")
96+
print(io, "\na zero decimal (e.g. 2.0^-n instead of 2^-n), or write 1/x^n, float(x)^-n, or (x//1)^-n")
9397
end
9498
break
9599
end

0 commit comments

Comments
 (0)