Bigfloat Esnext

A library for arbitrary precision decimal floating point arithmetic.
Alternatives To Bigfloat Esnext
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Angourimath62414 months ago13December 03, 2021127mitC#
New open-source cross-platform symbolic algebra library for C# and F#. Can be used for both production and research purposes.
Calc247
18 days ago8otherC
C-style arbitrary precision calculator
Javascript Biginteger1811264 years ago4April 15, 20143mitJavaScript
A big integer library for JavaScript
Imath102
2 months ago5otherC
Arbitrary precision integer and rational arithmetic library
Bcmath Extended6718112 months ago24February 09, 2022mitPHP
Extends php BCMath lib for missing functions like floor, ceil, round, abs, min, max, rand for big numbers. Also wraps existing BCMath functions.
Nim Stint65
a month agoAugust 20, 202218apache-2.0Nim
Stack-based arbitrary-precision integers - Fast and portable with natural syntax for resource-restricted devices.
Fermat61
35 months ago7June 27, 20214gpl-2.0PHP
A library providing math and statistics operations for numbers of arbitrary size.
Math45
a month ago1mitJavaScript
Complex special functions and common mathematical operations in JavaScript
Cldr Engine39178 days ago170April 18, 20221apache-2.0TypeScript
Internationalization and localization in Typescript with Unicode CLDR, batteries included
Polynomialroots.jl37
2 years ago6otherJulia
Fast complex polynomial root finder, with support for arbitrary precision calculations
Alternatives To Bigfloat Esnext
Select To Compare


Alternative Project Comparisons
Readme

BigFloat

A library for arbitrary precision decimal floating point arithmetic that can exactly represent all decimal fractions, unlike JavaScript's number data type which is 64-bit binary floating point.

Based on the original work by Douglas Crockford. This implementation is built upon ES native bigints.

This library provides three ways to make bigfloat operations:

  • A set of functions for a functional style approach
  • A BigFloat class with an API similar to that of Decimal.js
  • An evaluate() function that parses and resolves an expression

Basic usage

Functional style

import { make, string, sqrt } from "bigfloat-esnext";

string(sqrt(make("2")));               // "1.4142"

Class based

import { BigFloat } from "bigfloat-esnext";

new BigFloat("2").sqrt().toString();   // "1.4142"

The evaluate() function

evaluate(expression: string, precision?: number): string | boolean

The first argument can be any valid arithmetic or relational expression, including scientific e-notation. Precision should be a negative integer. Default is -4.

import { evaluate } from "bigfloat-esnext";

0.1 + 0.2 === 0.3;                     // false
evaluate("0.1 + 0.2 == 0.3");          // true

0.1 + 0.2;                             // 0.30000000000000004
evaluate("0.1 + 0.2");                 // "0.3"

1 + Number.EPSILON / 2;                // 1
evaluate(`1 + ${Number.EPSILON / 2}`); // "1.00000000000000011102230246251565"

evaluate("1 + 2.220446049250313e-16"); // "1.0000000000000002220446049250313"

evaluate(`4 >= ${Math.PI}`);           // true

Valid tokens:

  • Parenthesis: (,)
  • Number: Decimal, integer or scientific e-notation
  • Operator: Arithmetic +,-,/,*,** Relational ===,==,!==,!=,<,>,<=,>=

Change precision

import { BigFloat, set_precision } from "bigfloat-esnext";

new BigFloat(2).sqrt().toString();     // "1.4142"
set_precision(-10);
new BigFloat(2).sqrt().toString();     // "1.4142135623"

The bigfloat object

interface IBigFloat {
  coefficient: bigint;
  exponent: number;
}

Valid bigfloat made from primitives:

const bigfloat: IBigFloat {
  coefficient: 522299n,
  exponent: -4
};
Popular Arbitrary Precision Projects
Popular Mathematics Projects
Popular Mathematics Categories
Related Searches

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Typescript
Math
Mathematics
Cryptocurrency
Physics
Bigdecimal
Arbitrary Precision
Bignumber