Comments (11)
@RReverser: Can you look at that?
from jdataview.
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:
- 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. - For denormalized numbers, it seems we have to invert the expression
mantissa = Math.floor(value * Math.pow(2, mantSize - eMin));
to becomemantissa = Math.floor(value / Math.pow(2, eMin - mantSize));
, otherwise there is some numerical error. - The expression
if (exponent > eMin && exponent <= eMax)
becomesif (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.
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.
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.
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.
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.
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.
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.
I'll try using the built-in GitHub editor... thanks for the tip!
from jdataview.
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.
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)
- Uint64.toString fails for large numbers HOT 2
- Using jDataView in chrome throws Uncaught ReferenceError: NODE is not defined HOT 3
- Better support for negative bitLength HOT 11
- Use backing buffer/view's methods when available. HOT 5
- Use native methods for bit access HOT 4
- Remove string concatenation at runtime HOT 3
- Bitfields doesn't work well in littleEndian mode HOT 1
- Dist file without sourceMappingURL HOT 5
- it
- Bitfield API ignores endianness. HOT 2
- Question: Is jDataView runnable in web worker? HOT 1
- Question: How to convert the "uint16" value to half-precision float (i.e. "float16")? HOT 1
- Weird Float types (48 & 80 bit) HOT 1
- readString() with variable 7-bit based integer as prefix length HOT 1
- untar demo intersperses chunks of JavaScript in textareas HOT 1
- dataview constructor argument offset is invalid HOT 10
- Getting an error only after minification of dist/browser/jdataview.js? HOT 4
- Constuctor doesn't work the same as a real DataView? HOT 7
- Cannot use 'in' operator to search for 'Buffer' in undefined HOT 5
- Remove old fallbacks HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jdataview.