chipincode / sinful-math Goto Github PK
View Code? Open in Web Editor NEWSimple, safe floating-point math for node and the browser
Simple, safe floating-point math for node and the browser
Weird bug: sub(30, 0.00004999999999833333)
produces -0.0000499999999983333
for me.
sub( 9, 0.00004999999999833333)
produces 8.999950000000002
which is more or less correct.
That long number has 20 digits to the right of the decimal place, which my NodeJS won't normally produce. Trimming a digit or two off the end of the number will return the right value.
I'm not sure what's going on; just thought I'd bring it up.
adding small numbers return 0.
for example:
sinful.add(1e-7,1e-7) returns 0 instead of 2e-7.
However sinful.add(1e-6,1e-7) returns 0.000001
Looks like precision is set to 6. Is there a way to increase it to 9?
I have a number 7.471E-35
occurring in my code. When I use the add()
function from this library it incorrectly rounds or truncates this to 0:
node
Welcome to Node.js v14.18.1.
Type ".help" for more information.
> const {add} = require('sinful-math');
undefined
> b = 4.761E-35
4.761e-35
> add(b,0)
0
> b+0
4.761e-35
>
0
4.761e-35
here is a test case for the issue:
it("should divide big number by a divisor with large precision", function(){
assert.equal(divide(25, 0.000034567890123456789012345), 723214.5181760951)
})
I will submit a pull request to resolve this issue soon.
I started using this lib to help with some floating point issues I was having on a currency conversion function. It's been reliable for some time but today, using on a different project, I got a problem with a simple addition operation. I first saw in the browser and have reproduced in node as in the screen grab below:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.