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

the error message for ^ calls all unknown types "integer" #55960

Open
nsajko opened this issue Oct 1, 2024 · 3 comments
Open

the error message for ^ calls all unknown types "integer" #55960

nsajko opened this issue Oct 1, 2024 · 3 comments
Labels
error messages Better, more actionable error messages maths Mathematical functions

Comments

@nsajko
Copy link
Contributor

nsajko commented Oct 1, 2024

julia> π^Int(-1)
ERROR: DomainError with -1:
Cannot raise an integer x to a negative power -1.
Convert input to float.
Stacktrace:
 [1] throw_domerr_powbysq(::Float64, p::Int64)
   @ Base ./intfuncs.jl:302
 [2] power_by_squaring(x_::Irrational{:π}, p::Int64; mul::typeof(*))
   @ Base ./intfuncs.jl:327
 [3] power_by_squaring
   @ ./intfuncs.jl:316 [inlined]
 [4] ^(x::Irrational{:π}, p::Int64)
   @ Base ./intfuncs.jl:352
 [5] top-level scope
   @ REPL[1]:1

julia> isinteger(π)
false

NB: there's nothing special about π here, all unknown (not-floating-point?) types seem to be regarded as integer by the error message.

@nsajko nsajko added maths Mathematical functions error messages Better, more actionable error messages labels Oct 1, 2024
@oscardssmith
Copy link
Member

The bigger issue is that this should probably just work.

@nsajko
Copy link
Contributor Author

nsajko commented Oct 1, 2024

Made a separate issue about that: #55961

@nsajko
Copy link
Contributor Author

nsajko commented Oct 1, 2024

Here's a standalone example for this issue, independent of Irrational:

julia> struct S <: Real end

julia> Base.:(*)(::S, ::S) = S()

julia> Base.isone(::S) = false

julia> Base.:(-)(::S) = S()

julia> e = -1; S() ^ e
ERROR: DomainError with -1:
Cannot raise an integer x to a negative power -1.
Convert input to float.
Stacktrace:
 [1] throw_domerr_powbysq(::S, p::Int64)
   @ Base ./intfuncs.jl:302
 [2] power_by_squaring(x_::S, p::Int64; mul::typeof(*))
   @ Base ./intfuncs.jl:327
 [3] power_by_squaring
   @ ./intfuncs.jl:316 [inlined]
 [4] ^(x::S, p::Int64)
   @ Base ./intfuncs.jl:352
 [5] top-level scope
   @ REPL[5]:1

julia> versioninfo()
Julia Version 1.12.0-DEV.1282
Commit dd310849adb (2024-10-01 18:56 UTC)
Build Info:
  Official https://julialang.org release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 8 × AMD Ryzen 3 5300U with Radeon Graphics
  WORD_SIZE: 64
  LLVM: libLLVM-18.1.7 (ORCJIT, znver2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error messages Better, more actionable error messages maths Mathematical functions
Projects
None yet
Development

No branches or pull requests

2 participants