Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@which 2^(-1) directs to incorrect method #53691

Closed
putianyi889 opened this issue Mar 11, 2024 · 1 comment · Fixed by #53713
Closed

@which 2^(-1) directs to incorrect method #53691

putianyi889 opened this issue Mar 11, 2024 · 1 comment · Fixed by #53713

Comments

@putianyi889
Copy link
Contributor

putianyi889 commented Mar 11, 2024

julia> 2^(-1)
0.5

julia> @which 2^(-1)
^(x::T, p::T) where T<:Integer
     @ Base intfuncs.jl:310

^(x::T, p::T) where {T<:Integer} = power_by_squaring(x,p)

julia> Base.power_by_squaring(2,-1)
ERROR: DomainError with -1:
Cannot raise an integer x to a negative power -1.
Make x or -1 a float by adding a zero decimal (e.g., 2.0^-1 or 2^-1.0 instead of 2^-1)or write 1/x^1, float(x)^-1, x^float(-1) or (x//1)^-1.
Stacktrace:
 [1] throw_domerr_powbysq(::Int64, p::Int64)
   @ Base .\intfuncs.jl:265
 [2] power_by_squaring(x_::Int64, p::Int64)
   @ Base .\intfuncs.jl:286
 [3] top-level scope
   @ REPL[79]:1

It's because 2^(-1) is done through literal_pow.

@code_lowered and @less have the same problem.

julia> @code_lowered 2^(-1)
CodeInfo(
1%1 = Base.power_by_squaring(x, p)
└──      return %1
)
@thofma
Copy link
Contributor

thofma commented Mar 11, 2024

Dup of #21014?

@vtjnash vtjnash closed this as completed Mar 11, 2024
mbauman added a commit that referenced this issue Apr 3, 2024
…w` case. (#53713)

The macros `@which`, `@edit`, `@functionloc`, `@less` from `InteractiveUtils`, if
applied to the case of literal powers, like `a^12` or `2^-1` used to direct the
user to function `^`, while the compiler generates code for `Base.literal_pow`.

Now the user is shown the code the compiler generates.

Fixes #53691
Fixes #43337
Fixes #21014

Co-authored-by: Matt Bauman <mbauman@juliahub.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants