Giter VIP home page Giter VIP logo

Comments (11)

vjeux avatar vjeux commented on June 25, 2024

@RReverser: Can you look at that?

from jdataview.

mmthomas avatar mmthomas commented on June 25, 2024

Sorry that I don't have a diff/pull request to do this; here's the revised part that fixes the problem for 64-bit denormalized numbers.

Three issues:

  1. The exponent should not be incremented if the number is denormalized. The code snippet below elides the exponent += eMax; statement that was being done at the end of the if blocks, and instead calculates it for each of the cases.
  2. For denormalized numbers, it seems we have to invert the expression mantissa = Math.floor(value * Math.pow(2, mantSize - eMin)); to become mantissa = Math.floor(value / Math.pow(2, eMin - mantSize));, otherwise there is some numerical error.
  3. The expression if (exponent > eMin && exponent <= eMax) becomes if (exponent >= eMin && exponent <= eMax), that is, the lower bound is now inclusive.
    ...

    if (value === 0) {
        exponent = 0;
        mantissa = 0;
    } else
    if (isNaN(value)) {
        exponent = 2 * eMax + 1;
        mantissa = 1;
    } else
    if (value === Infinity) {
        exponent = 2 * eMax + 1;
        mantissa = 0;
    } else {
        exponent = Math.floor(Math.log(value) / Math.LN2);
        if (exponent >= eMin && exponent <= eMax) {
            mantissa = Math.floor((value * Math.pow(2, -exponent) - 1) * Math.pow(2, mantSize));
            exponent += eMax;
        } else {
            mantissa = Math.floor(value / Math.pow(2, eMin - mantSize));
            exponent = 0;
        }
    }

    var b = [];
    ...

from jdataview.

vjeux avatar vjeux commented on June 25, 2024

You seem to be really close to have a pull request :) You sure you don't want to take the extra 20 minutes to write it down along with adding the test cases that you mentioned. It'll be really helpful to people using the library if we can give proper values all the time :p

from jdataview.

mmthomas avatar mmthomas commented on June 25, 2024

Unfortunately I don't have GIT set up on any of the machines I have access to right now. :( Unless you can tell me of another way. :)

from jdataview.

RReverser avatar RReverser commented on June 25, 2024

Thanks for your investigation. I wrote that code using experimental tests (TDD-way :)) according to standards described in official IEEE.754 specification, but for sure could miss something...

Regarding your last question - you can edit file directly from GitHub, there is built-in editor, which allows you to fork + edit + send pull request at once.

from jdataview.

RReverser avatar RReverser commented on June 25, 2024

Wait, seems I start to recalling. As far as I remember, denormalized values are actually just form of float representation and I decided to store them always in normalized way. And parsed values should be equal in both binary representation, so I wonder if it really breaks something for you?

from jdataview.

vjeux avatar vjeux commented on June 25, 2024

Denormalized numbers are used to express very small numbers. On Float32, they can encode numbers from 2^-149 to 2^-126. If you only have normalized numbers, you cannot represent numbers smaller than 2^-126.

See this website for more information about them: http://steve.hollasch.net/cgindex/coding/ieeefloat.html

from jdataview.

mmthomas avatar mmthomas commented on June 25, 2024

It does break things. :) Denormalized values are valid IEEE based representations of floating point numbers, and you can generate them using functions like Math.pow(2, -1050). So we need to be able to store and retrieve them.

from jdataview.

mmthomas avatar mmthomas commented on June 25, 2024

I'll try using the built-in GitHub editor... thanks for the tip!

from jdataview.

RReverser avatar RReverser commented on June 25, 2024

Reviewed changes. Seems I handled them but made mistake in code in last condition and didn't have tests to figure that out (all the others seems to do the same actions as before, you just removed "exponent += eMax;" adding that number in each separate case instead.
Thanks for fixing and explanations though!

from jdataview.

mmthomas avatar mmthomas commented on June 25, 2024

No problem! You did a great job on that code; the denormalized values are definitely an unusual use case, and not very well documented. Cheers!

from jdataview.

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.