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

Comparison with Rational #108

Closed
jmkuhn opened this issue Mar 18, 2020 · 2 comments · Fixed by #114
Closed

Comparison with Rational #108

jmkuhn opened this issue Mar 18, 2020 · 2 comments · Fixed by #114
Labels

Comments

@jmkuhn
Copy link
Contributor

jmkuhn commented Mar 18, 2020

julia> d64"0.1" == 1//10
false

This should be true. Fixing this (and issue #79) is important to get hash() working (issue #97).

@stevengj
Copy link
Member

stevengj commented Mar 29, 2020

This is calling ==(x::AbstractFloat, q::Rational), which assumes binary floating-point.

A correct implementation is probably something like:

function ==(x:: DecimalFloatingPoint, q::Rational)
    if isfinite(x)
        ispow10(q.den) & (x*q.den == q.num)
    else
        x == q.num/q.den
    end
end

@stevengj stevengj added the bug label Mar 29, 2020
@jmkuhn
Copy link
Contributor Author

jmkuhn commented May 5, 2020

Also need to implement Base.decompose()

julia> d64"0.3" < 1//3
ERROR: MethodError: no method matching decompose(::Dec64)
Closest candidates are:
  decompose(::BigFloat) at hashing2.jl:133
  decompose(::Float64) at hashing2.jl:122
  decompose(::Float32) at hashing2.jl:111
  ...
Stacktrace:
 [1] <(::Dec64, ::Rational{Int64}) at ./rational.jl:316
 [2] top-level scope at REPL[3]:1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants