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

no method round(MathConst{:π}) #5561

Closed
ihnorton opened this issue Jan 26, 2014 · 11 comments
Closed

no method round(MathConst{:π}) #5561

ihnorton opened this issue Jan 26, 2014 · 11 comments
Labels
good first issue Indicates a good issue for first-time contributors to Julia help wanted Indicates that a maintainer wants help on an issue or pull request

Comments

@ihnorton
Copy link
Member

julia> round(pi)
ERROR: no method round(MathConst{:π})

reported here

@ihnorton
Copy link
Member Author

The Forio tutorial could be updated to use the 2-arg form. But there is also inconsistent behavior like this:

julia> round(-pi)
-3.0

@JeffBezanson
Copy link
Member

Other than conversion-related functions, only +,-,*,/,^ are implemented for MathConsts. Adding every function is not practical.

So, we obviously need a more systematic approach for "exotic" kinds of numbers that are not going to have every function implemented just for them. MathConst and Float16 are good examples --- rather than re-implement all of libm for them, we want to convert to a standard type, then possibly convert back. Perhaps a function like stdfloat(x) that converts x to an appropriate standard type (Float32, Float64, or BigFloat --- those should be sufficient).

@nolta
Copy link
Member

nolta commented Jan 27, 2014

What about just bringing back the old definition of pi, but keeping the MathConst π? Then we get the best of both worlds.

@StefanKarpinski
Copy link
Member

This could be partially handled with generic apply. I.e. apply(f::Function, x::MathConst) = f(float(x)).

@StefanKarpinski
Copy link
Member

@nolta: forcing people to use Unicode to get a correctly behaved generic pi seems wrong.

@nolta
Copy link
Member

nolta commented Jan 27, 2014

Call it Pi then, just like Mathematica.

@JeffBezanson
Copy link
Member

A definition like that would be ambiguous with an ordinary definition of a particular generic function for a type like Real.

@ihnorton ihnorton mentioned this issue Feb 25, 2014
@quinnj
Copy link
Member

quinnj commented Jun 5, 2014

We could just prompt the user to do their own conversion, though that still requires a round(::MathConst) definition of sorts, unless the apply thing could be made to work (i.e. trying to apply any function to a MathConst would simple error with, please convert me to Float64, BigFloat, etc)

@StefanKarpinski StefanKarpinski added help wanted Indicates that a maintainer wants help on an issue or pull request good first issue Indicates a good issue for first-time contributors to Julia labels Jun 24, 2016
@NHDaly
Copy link
Member

NHDaly commented Jul 25, 2017

This issue is marked as up for grabs and intro issue, but in light of the conversation at #21535 (Irrational arithmetic is a slippery, dangerous slope), this seems like more of a decision?

@tpapp
Copy link
Contributor

tpapp commented Jan 25, 2018

Would the missing method

julia> round(Int, pi)
ERROR: MethodError: no method matching round(::Type{Int64}, ::Irrational{:π})
Closest candidates are:
  round(::Type{T<:Integer}, ::Integer) where T<:Integer at int.jl:524
  round(::Type{T<:Integer}, ::Float16) where T<:Integer at float.jl:356
  round(::Type{T<:Union{Signed, Unsigned}}, ::BigFloat) where T<:Union{Signed, Unsigned} at mpfr.jl:229
  ...

julia> VERSION
v"0.7.0-DEV.3507"

fall under this issue? Asking because so much of the interface changed since it was opened.

round(pi, [digits]) works.

@KristofferC
Copy link
Member

round(pi) now works. For adding additional methods, closing based on #5561 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Indicates a good issue for first-time contributors to Julia help wanted Indicates that a maintainer wants help on an issue or pull request
Projects
None yet
Development

No branches or pull requests

8 participants