-
-
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
for most functions if f(::Int64)::Float64 then f(::BigInt)::BigFloat #17474
Comments
trigamma
, digamma
and zeta
should return BigFloats, when applied to BigInts
I made a script to search for these cases: https://gist.github.com/oxinabox/36e939544c2d93c1baa4d34fca776622 Ran it on 0.4.6 (my 0.5 is not accessibe right now, but I think the script should work on 0.5) Returns a Float64
Throw errorsAnd the following functions which throw errors on The error in all 6 of these cases is
Reasonable/required
|
Thanks for chasing this up. The main problem here is that we don't have |
It seems we do have methods for We should probably change the behaviour of
|
Ideally it would not be throwing errors, but instead not saying it has a method defined on BigInt in the first place. |
If Many of the foo{T<:Union{Integer,Rational}}(x::Union{T,Complex{T}}) = foo(float(x))
foo{T<:Union{Float16,Float32}}(x::Union{T,Complex{T}}) = oftype(x, foo(f64(x))) |
Instead of foo{T<:Union{Integer,Rational}}(x::Union{T,Complex{T}}) = foo(float(x)) what's wrong with foo(x::Number) = foo(float(x)) (which also works for |
Oh right, the mess in #14979... We would also need foo(x::FloatingPoint) = throw(MethodError(foo,(x,))) |
Probably to be absolutely sure you don't get circular method calls you would need function foo(x::Number)
y = float(x)
typeof(y) === typeof(x) && throw(MethodError(foo, (x,)))
return foo(y)
end (Think about what |
Manually throwing It is a bit weird, and potentially confusing if when doing some protyping in the REPL,
then when I run
Why would the The reverse is also true, when ever I get a method error, my first step is to open the REPL and call In short, any time |
@oxinabox, it is a common pattern in Julia to dispatch from a generic signature like |
I closed this in code that was eventually merged in: |
As I learnt when doing #17447 (comment)
the expectation is that, for a function
f
(eg gamma, exp2)if
f(::Int64)::Float64
thenf(::BigInt)::BigFloat
And for the most part this is true (indeed I added in the PR test cases to ensure it).
I have found 3 exceptions to it, all functions from a part of math the I've not really dealt with much.
zeta
,digamma
, andtrigamma
digamma
This is the simple case.
The fallback definition for BigInt, is falling down to
digamma(z::Number) at special/gamma.jl:368
and so never ends up calling
digamma(x::BigFloat) at mpfr.jl:450
, which is the natural call backzeta
So it is working fine for complex numbers, which is what most people care about (From the little I know of the Riemann zeta function).
For
BigInt
it is hittingzeta(x::Integer) at special/gamma.jl:462
Which is similar to the issue for
digamma
however we also see that
zeta(big"1.0") != zeta(big("1"))
(ignoring type).NaN !=inf
. which is more concerning.Divining what the correct answer for
zeta(1)
should be, I leave to better informed minds than my own.WolframAlpha says it is "Complex Infinity"
Trigamma
trigamma is not defined for BigFloat, or BigInt, so perhaps it doesn't belong here, but just pointing it out since i spotted it.
The text was updated successfully, but these errors were encountered: