{"id":23113069,"url":"https://github.com/daninet/exactnumber","last_synced_at":"2025-08-16T19:31:49.956Z","repository":{"id":57818928,"uuid":"527692457","full_name":"Daninet/exactnumber","owner":"Daninet","description":"Arbitrary-precision decimals. Enables making math calculations with rational numbers, without precision loss.","archived":false,"fork":false,"pushed_at":"2025-08-06T18:52:25.000Z","size":706,"stargazers_count":18,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-06T20:37:32.773Z","etag":null,"topics":["approximation","arbitrary-precision","bigdecimal","decimals","javascript","math","rational-numbers","typescript"],"latest_commit_sha":null,"homepage":"https://npmjs.org/package/exactnumber","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Daninet.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-08-22T18:47:49.000Z","updated_at":"2025-08-06T18:51:59.000Z","dependencies_parsed_at":"2025-08-06T20:23:54.783Z","dependency_job_id":null,"html_url":"https://github.com/Daninet/exactnumber","commit_stats":{"total_commits":57,"total_committers":1,"mean_commits":57.0,"dds":0.0,"last_synced_commit":"bf8efdc71436a6479f8cba9423eb9812f86364e0"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/Daninet/exactnumber","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Daninet%2Fexactnumber","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Daninet%2Fexactnumber/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Daninet%2Fexactnumber/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Daninet%2Fexactnumber/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Daninet","download_url":"https://codeload.github.com/Daninet/exactnumber/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Daninet%2Fexactnumber/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270763106,"owners_count":24641007,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-16T02:00:11.002Z","response_time":91,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["approximation","arbitrary-precision","bigdecimal","decimals","javascript","math","rational-numbers","typescript"],"created_at":"2024-12-17T02:26:56.193Z","updated_at":"2025-08-16T19:31:49.917Z","avatar_url":"https://github.com/Daninet.png","language":"TypeScript","readme":"# ExactNumber\n\n[![npm package](https://img.shields.io/npm/v/exactnumber.svg)](http://npmjs.org/package/exactnumber)\n[![codecov](https://codecov.io/gh/Daninet/exactnumber/branch/master/graph/badge.svg)](https://codecov.io/gh/Daninet/exactnumber)\n[![Build status](https://github.com/Daninet/exactnumber/workflows/Build/badge.svg?branch=master)](https://github.com/Daninet/exactnumber/actions)\n[![JSDelivr downloads](https://data.jsdelivr.com/v1/package/npm/exactnumber/badge)](https://www.jsdelivr.com/package/npm/exactnumber)\n\nArbitrary-precision decimals. Enables making math calculations with rational numbers, without precision loss.\n\n## Features\n\n- Works with arbitrary large numbers without precision loss\n- All fractions can be represented as repeating decimals like `1.23(45)`\n- This repeating decimal format (`1.23(45)`) can also be parsed back\n- Works with all number bases between `2` and `16`\n- **No special values** like `NaN`, `Infinity` or `-0`.\n- **No silent errors**: it throws errors immediatelly when a confusing parameter is received (e.g. 0/0)\n- Supports bitwise operators (`and`, `or`, `xor`, `shiftLeft`, `shiftRight`)\n- Supports all modern browsers, web workers, Node.js and Deno\n- Includes TypeScript type definitions: [documentation](https://daninet.github.io/exactnumber)\n- Zero external dependencies\n- Under the hood, it relies on the `BigInt` type. It automatically switches back and forth between fixed-precision and fractional representations.\n- Tries to deliver the best possible performance\n- 100% open source + MIT license\n\n## Comparision with built-in numbers\n\n```js\nimport { ExactNumber as N } from 'exactnumber';\n\n1 + 0.36 // 1.3599999999999999\nN(1).add('0.36').toString() // 1.36\n\n(1 / 49) * 49 // 0.9999999999999999\nN(1).div(49).mul(49).toString() // 1\n\n10e16 + 5 // 100000000000000000\nN('10e16').add(5).toString() // 100000000000000005\n\n1 / 3 // 0.3333333333333333\nN(1).div(3).toString() // 0.(3)\n\n2**32 \u003e\u003e 32 // 0\nN(2).pow(32).shiftRight(32).toString() // 1\n```\n\n## Installation\n\n```\nnpm i exactnumber\n```\n\nIt can also be used directly from HTML (via [jsDelivr](https://www.jsdelivr.com/package/npm/exactnumber)):\n\n```html\n\u003c!-- loads the full, minified library into the global `exactnumber` variable --\u003e\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/exactnumber\"\u003e\u003c/script\u003e\n\n\u003c!-- or loads the non-minified library --\u003e\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/exactnumber/dist/index.umd.js\"\u003e\u003c/script\u003e\n```\n\n## Usage\n\n```js\nimport { ExactNumber as N } from 'exactnumber';\n\nN(1).add('3').toString(); // 4\n\nN('1/7').add('1/10').toFraction(); // 17/70\n\nN('1/7').toString(); // 0.(142857)\nN('1/7').toString(6); // 0.(05)\nN('1/7').toFixed(3); // 0.142\nN('1/7').trunc(3).toString(); // 0.142\nN('0.(3)').add('0.(6)').toString(); // 1\n\nN('0b1100').bitwiseAnd('0b1010').toString(2); // 1000\n\nN.max('1/1', '10/2', 3).toString(); // 5\nN.fromBase('123', 4).toString(); // 27\n\n```\n\n## Functions\n\n- Addition / subtraction: `add()`, `sub()`\n- Multiplication / division: `mul()`, `div()`, `divToInt()`\n- Exponentiation: `pow()`\n- Modular arithmetic: `mod()`, `powm()`\n- Getting the sign / absolute value: `sign()`, `abs()`\n- Negation / inversion: `neg()`, `inv()`\n- Integer and fractional parts: `intPart()`, `fracPart()`\n- Comparisons: `cmp()`, `eq()`, `lt()`, `lte()`, `gt()`, `gte()`\n- Special comparisons: `isZero()`, `isOne()`\n- Type testing: `isInteger()`\n- Rounding: `round()`, `roundToDigits()`, `floor()`, `ceil()`, `trunc()`\n- Bitwise operators: `bitwiseAnd()`, `bitwiseOr()`, `bitwiseXor()`, `shiftLeft()`, `shiftRight()`\n- Clamping: `clamp()`\n- Fraction helper: `getFractionParts()`\n- Normalization / simplifying fractions: `normalize()`\n- String output: `toFixed()`, `toExponential()`, `toPrecision()`, `toString()`, `toFraction()`\n- Number output: `toNumber()`\n- GCD, LCM: `ExactNumber.gcd()`, `ExactNumber.lcm()`\n- Minimum, maximum: `ExactNumber.min()`, `ExactNumber.max()`\n- Parsing numbers in different bases: `ExactNumber.fromBase()`\n- Range generator: `ExactNumber.range()`\n\n## Rounding modes\n\n- `NEAREST_TO_POSITIVE` - Rounds to nearest number, with ties rounded towards +Infinity. Similar to Math.round().\n- `NEAREST_TO_NEGATIVE` - Rounds to nearest number, with ties rounded towards -Infinity.\n- `NEAREST_TO_EVEN` - Rounds to nearest number, with ties rounded towards the nearest even number.\n- `NEAREST_TO_ZERO` - Rounds to nearest number, with ties rounded towards zero.\n- `NEAREST_AWAY_FROM_ZERO` - Rounds to nearest number, with ties rounded away from zero.\n\n- `TO_POSITIVE` - Rounds towards +Infinity. Similar to Math.ceil().\n- `TO_NEGATIVE` - Rounds towards -Infinity. Similar to Math.floor().\n- `TO_ZERO` - Rounds towards zero. Similar to Math.trunc().\n- `AWAY_FROM_ZERO` - Rounds away from zero\n\n## Modulo variants\n\n- `TRUNCATED`\n- `FLOORED`\n- `EUCLIDEAN`\n\nRead more about them [here](https://en.wikipedia.org/wiki/Modulo_operation).\n\n## Copyright\n\nLicense: MIT\n\nCopyright © 2025 Dani Biró\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaninet%2Fexactnumber","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaninet%2Fexactnumber","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaninet%2Fexactnumber/lists"}