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

div(pi,pi), rem(pi,pi) etc undefined #26701

Closed
JeffreySarnoff opened this issue Apr 4, 2018 · 8 comments
Closed

div(pi,pi), rem(pi,pi) etc undefined #26701

JeffreySarnoff opened this issue Apr 4, 2018 · 8 comments
Labels
maths Mathematical functions

Comments

@JeffreySarnoff
Copy link
Contributor

JeffreySarnoff commented Apr 4, 2018

This issue was raised in this discourse thread

possible remedy

Base.Math.mod(::Irrational{T}, ::Irrational{T}) where T = 0.0
Base.Math.rem(::Irrational{T}, ::Irrational{T}) where T = 0.0
Base.Math.div(::Irrational{T}, ::Irrational{T}) where T = 1.0
Base.Math.fld(::Irrational{T}, ::Irrational{T}) where T = 1.0
Base.Math.cld(::Irrational{T}, ::Irrational{T}) where T = 1.0
Base.Math.divrem(::Irrational{T}, ::Irrational{T}) where T = 1.0, 0.0
Base.Math.fldmod(::Irrational{T}, ::Irrational{T}) where T = 1.0, 0.0

and these, as currently evaluated, are anomalous (suggestions follow)

# fn in {div, fld, cld}
fn( Inf, x:::isfinite(x)) =  Inf
fn(-Inf, x:::isfinite(x)) = -Inf

# fn in {rem, mod} 
fn( Inf, x:::isfinite(x)) =  0.0
fn(-Inf, x:::isfinite(x)) = -0.0
@StefanKarpinski
Copy link
Member

Since operations with irrationals default to Float64 results, those should probably all return 0.0 and 1.0.

@tomaklutfu
Copy link
Contributor

May not be the same thing but https://discourse.julialang.org/t/comparison-of-same-irrationals-by-throws-error/1342 . May be even more for the same irrationals.

@JeffreySarnoff
Copy link
Contributor Author

JeffreySarnoff commented Apr 4, 2018

re returning 0.0 and 1.0 (yes, the .0s were implied) :) fixed above

@simonbyrne
Copy link
Contributor

For the infinities, see #26694.

@JeffreySarnoff
Copy link
Contributor Author

all of these paths lead to good places

@GunnarFarneback
Copy link
Contributor

It looks natural to extend the list at
https://github.com/JuliaLang/julia/blob/master/base/irrationals.jl#L123

for op in Symbol[:+, :-, :*, :/, :^]
    @eval $op(x::AbstractIrrational, y::AbstractIrrational) = $op(Float64(x),Float64(y))
end

@JeffBezanson JeffBezanson added the maths Mathematical functions label Apr 4, 2018
@Nosferican
Copy link
Contributor

Nosferican commented Apr 8, 2018

Maybe this could be added to the PR, (in its correct form)

median(AbstractArray{S, Integer}) where S<:Irrational = S

similar to how

mode([π,π]) == π

mean could probably go this way of specialized methods for Irrational.

@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.

@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
maths Mathematical functions
Projects
None yet
Development

No branches or pull requests

8 participants