Git Product home page Git Product logo

Comments (1)

dzhang314 avatar dzhang314 commented on June 27, 2024

Hey @nsajko, thanks for discovering this surprising behavior! It seems that, in this case, the extra limb computed in clean mode is not quite cancelled out in the multiplication x * inv(x), producing a number that is very slightly different from 1.0.

This behavior is counterintuitive but actually correct. The number (1/3)^100 cannot be exactly represented as a terminating decimal in base 2, so you should not expect inv(3.0^100) to be the exact multiplicative inverse of 3^100. Indeed, if we compare using BigFloat:

julia> MultiFloats.use_clean_multifloat_arithmetic(20)

julia> Float64x{13}(3.0^100) * inv(Float64x{13}(3.0^100))
1.00000000000000000 [ ... lots of zeroes ... ] 000009233803766632279

julia> setprecision(BigFloat, 1000)

julia> BigFloat(3.0^100) * BigFloat(inv(Float64x{13}(3.0^100)))
1.00000000000000000 [ ... lots of zeroes ... ] 000009233803766632279027870659735403696888168679729487436063148964080335784965191272233867971

You can see that clean mode correctly produces a more accurate result. Therefore, there is no bug here. The only issue is the false expectation that isone(x * inv(x)) hold for any x whose multiplicative inverse cannot be exactly represented.

from multifloats.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.