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

Cryptic error for Complex(::Irrational) #22878

Closed
malmaud opened this issue Jul 20, 2017 · 8 comments
Closed

Cryptic error for Complex(::Irrational) #22878

malmaud opened this issue Jul 20, 2017 · 8 comments
Labels
complex Complex numbers maths Mathematical functions

Comments

@malmaud
Copy link
Contributor

malmaud commented Jul 20, 2017

julia> complex(pi)
ERROR: MethodError: Cannot `convert` an object of type Int64 to an object of type Irrational{:π}
@JeffBezanson JeffBezanson added complex Complex numbers maths Mathematical functions labels Jul 20, 2017
@mschauer
Copy link
Contributor

That is

zero(pi)
ERROR: MethodError: Cannot `convert` an object of type Int64 to an object of type Irrational{:π}

@strickek
Copy link
Contributor

or here?

julia> convert(Irrational, 0)
ERROR: MethodError: Cannot `convert` an object of type Int64 to an object of type Irrational
This may have arisen from a call to the constructor Irrational(...),
since type constructors fall back to convert methods.

@malmaud
Copy link
Contributor Author

malmaud commented Jul 23, 2017

Should be pick a default reasonable precision, like Float64, to make complex(pi) work? Or just add a more understandable error message?

@tkelman
Copy link
Contributor

tkelman commented Jul 23, 2017

See the last remaining bullet on #21204, cc @giordano

giordano added a commit to giordano/julia that referenced this issue Jul 23, 2017
`complex(x::Irrational)` cannot create a `Complex{Irrational}` instance, we have
to fall back on some other type, `Complex{Float64}` seems a reasonable option.

Closes JuliaLang#22878, see JuliaLang#21204.
giordano added a commit to giordano/julia that referenced this issue Jul 24, 2017
Create a `Complex{Real}` instance which preserves precision of the irrational
number.

Closes JuliaLang#22878, see JuliaLang#21204.
@giordano
Copy link
Contributor

giordano commented Oct 1, 2017

The decision in PR #22928 was to keep the error and don't provide a default behavior. I guess this ticket can be closed, unless someone wants to improve the error message.

@malmaud
Copy link
Contributor Author

malmaud commented Oct 3, 2017

I think this should stay open until the error is approved.

@perrutquist
Copy link
Contributor

complex(pi) is one of many methods that would start working if zero(pi) were defined.

@vtjnash
Copy link
Member

vtjnash commented Apr 8, 2021

We discussed this on triage, and felt that it is better to be explicit about the transforms for irrational numbers into the appropriate computational types and not add more methods to them.

In this way, this type could be viewed as being similar to undef, that exist as a token to pass to various constructors, but is not itself a fully-fledged type (another example of this may be I in LinearAlgebra).

@vtjnash vtjnash closed this as completed Apr 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
complex Complex numbers maths Mathematical functions
Projects
None yet
Development

No branches or pull requests

8 participants