-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
rationalize
method for integer
#43564
Comments
The main challenge is simply that it is defined to be an approximation from a decimal number, while integer conversion is always exact:
|
Yes, I see the I don’t think this method should only limit to approximation of decimal number, a rational number should be a number that can be expressed as the quotient of two integers, so it is reasonable to make the BTW, from my point, I would use the julia> arr = [1.2, 2, 3.4]
julia> rationalize(arr)
Error…… |
You would use broadcasting for this: julia> arr = [1.2, 2, 3.4]
3-element Vector{Float64}:
1.2
2.0
3.4
julia> rationalize.(arr)
3-element Vector{Rational{Int64}}:
6//5
2//1
17//5 |
@dkarrasch Yes, the broadcasting is working, but in your example, the integer 2 is first being converted to a floating number Then the I think adding the |
But that has nothing to do with the |
Thanks for your immediate response! Yes, the type promotion happened after we created the array, the problem is, for example, if I pass an integer to julia> rationalize(1)
ERROR:... Or, if I pass an integer array to julia> rationalize.([1, 2, 3])
ERROR:... |
Yes, but all of this has nothing to do with a missing method of |
Wow thanks! Didn’t notice it at first That PR is adding the relating method~ So I would close this issue😄 |
Hello guys, I notice the
rationalize
method is only supporting floating point numbers, and support for complex floating point numbers are in process, I think maybe this method should also support rationalizing integer.In Matlab, there are
rats
method to get rationalized expression of any number, floating point numbers, complex numbers and integer.And in python, there is also integer numbers rationalizing method.
So I think the
rationalize(x::Integer; tol::Real)
should be included in this method.Would be happy to hear your thoughts.
The text was updated successfully, but these errors were encountered: