Giter Site home page Giter Site logo

uzyn / bigdenary Goto Github PK

View Code? Open in Web Editor NEW
11.0 3.0 2.0 77 KB

๐Ÿฆ•๐Ÿงฎ Arbitrary-length decimal library, implemented with ES2020's native BigInt.

Home Page: https://deno.land/x/bigdenary

License: MIT License

TypeScript 100.00%
bignum bignumber bigint decimal decimals bigdecimals javascript typescript deno es6

bigdenary's People

Contributors

uzyn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

77it

bigdenary's Issues

(100 / 3) * 3 != 100 and (100 / 3) + (100 / 3) + (100 / 3) != 100

Hi,
I found an issue I want to highlight, curious about the position of the maintainer of this library on it.

I found that for bigdenary (100 / 3) * 3 != 100 and (100 / 3) + (100 / 3) + (100 / 3) != 100

the failing test are the following

Deno.test("BigDenary: (100 / 3) + (100 / 3) + (100 / 3) == 100", () => {
	const b_d100 = new BigDenary(100);
	const b_d33 = b_d100.div(3);
	const b_d100sum = new BigDenary(0).add(b_d33).add(b_d33).add(b_d33);
	assert(b_d100.eq(b_d100sum));
});

Deno.test("BigDenary: (100 / 3) * 3 == 100", () => {
	const b_d100 = new BigDenary(100);
	const b_d100mul = new BigDenary(100).div(3).mul(3);
	assert(b_d100.eq(b_d100mul));
});

The tests succeed when a BigDenary is converted to number with valueOf(), because valueOf() internally convert to string and then uses parseFloat() for the conversion to number, and because the converted string has more than 14 decimals, the returned number is rounded.

I decided then to test also decimal.js and number object, and I found that: number process them correctly (failing on others) while decimal.js fails at them as this library.

Test file attached.

For completeness, I also tested C #, and using the decimal type the problem is not present:

	decimal d100 = 100;
	decimal d33 = d100/ 3;
	decimal d100sum = d33 + d33 + d33;
	decimal d100mul = d33 * 3;
	Console.WriteLine(d33);
	Console.WriteLine(d100 == d100sum);
	Console.WriteLine(d100sum);
	Console.WriteLine(d100 == d100mul);
	Console.WriteLine(d100mul);

test.txt

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.