{"id":15355862,"url":"https://github.com/fibo/arithmetica","last_synced_at":"2025-08-09T09:31:53.491Z","repository":{"id":161434219,"uuid":"636136943","full_name":"fibo/arithmetica","owner":"fibo","description":"arbitrary-precision arithmetic operators for Rational numbers, supporting repeating decimals","archived":false,"fork":false,"pushed_at":"2025-07-01T04:57:57.000Z","size":164,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-01T04:59:54.509Z","etag":null,"topics":["arbitrary-precision","floating-point","math","rational-numbers"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/fibo.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2023-05-04T07:48:55.000Z","updated_at":"2025-07-01T04:57:47.000Z","dependencies_parsed_at":"2023-09-27T14:12:48.106Z","dependency_job_id":"42916ccc-1fc1-42d5-a51b-d4d3d2e68d84","html_url":"https://github.com/fibo/arithmetica","commit_stats":{"total_commits":68,"total_committers":1,"mean_commits":68.0,"dds":0.0,"last_synced_commit":"c36ad222615b38cdb17828321ba16dc51e0cc93b"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/fibo/arithmetica","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fibo%2Farithmetica","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fibo%2Farithmetica/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fibo%2Farithmetica/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fibo%2Farithmetica/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fibo","download_url":"https://codeload.github.com/fibo/arithmetica/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fibo%2Farithmetica/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268177618,"owners_count":24208381,"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-01T02:00:08.611Z","response_time":67,"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":["arbitrary-precision","floating-point","math","rational-numbers"],"created_at":"2024-10-01T12:26:03.233Z","updated_at":"2025-08-09T09:31:53.483Z","avatar_url":"https://github.com/fibo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# arithmetica\n\n\u003e arbitrary-precision arithmetic operators for Rational numbers, supporting repeating decimals\n\n**ToC**\n\n- [Installation](#installation)\n- [Rational numbers](#rational-numbers)\n- [Types](#types)\n- [Features](#features)\n- [Operators](#operators)\n- [Utils](#utils)\n- [License](#license)\n\n## Installation\n\nWith [npm](https://www.npmjs.com/) do\n\n```sh\nnpm install arithmetica\n```\n\nThis package is implemented with ECMAScript modules. CommonJS is not supported.\n\nNo dependencies are used at all.\n\n## Rational numbers\n\nIn Mathematics a [Rational number](https://en.wikipedia.org/wiki/Rational_number) is a number that can be expressed as a fraction of two integers, that is `a/b` where _a_ and _b_ are integers and _b_ is not zero.\n\nA _Rational_ number can be represented by a string, for example:\n- `'1'`\n- `'-12'`\n- `'0.5'`\n\nIt may have [repeating decimals](https://en.wikipedia.org/wiki/Repeating_decimal), when the number of decimal digits in the decimal representation is **infinite and periodic**. For example `1/3` is `0.33333...`.\n\n## Types\n\nThe `Rational` type is a string that represents a rational number, where:\n\n  - Decimal separator is `.` character.\n  - Exponential notation is not allowed. Values like `'1e3'` or `'1.2e-3'` are not valid.\n  - Integer part can be omitted. Values like `'.5'` or `'-.5'` are valid.\n  - Strings can be arbitrary long; the only limits are your computer's memory and the BigInt implementation.\n\nExamples of (finite) rational numbers:\n  - `'1'`\n  - `'-12'`\n  - `'1.23456789'`\n\nA _repeating decimal_ is represented by a string like,\n\n```\n\u003cInteger\u003e.\u003cDecimalFixedPart\u003e_\u003cDecimalRepeatingPart\u003e\n```\n\nFor example:\n  - `'0._6'`: the fraction 1/6, that is 0.666666666666...\n  - `'-1.23_456'`: the number -1.23456456456456...\n\n\nThe `MaybeRational` type is the union of types that can be coerced to a `Rational`, i.e. `string`, `number` and `bigint`.\n\n\nThe `Rational` type is used by operators as return type.\nThe `MaybeRational` types is used by operators as argument.\n\n## Features\n\nYou probably already aware of _floating point issues_ such as `0.1 + 0.2 != 0.3` or `0.1 * 0.2 != 0.02`; this occurs in JavaScript as well as many other languages.\nOperators in the `arithmetica` package implement arbitrary-precision arithmetic. For example:\n\n```js\nimport { add, mul } from 'arithmetica';\n\nadd(0.1, 0.2); // '0.3'\nmul(0.1, 0.2); // '0.02'\n```\n\nArguments are coerced, you can pass a `number`, `bigint` or `string`.\n\n```js\nadd('1', 2n); // '3'\n```\n\nYou can deal with _repeating decimals_.\n\n```js\nimport { add, div } from 'arithmetica';\n\ndiv(1, 3); // '0._3'\nadd('0._3', 1); // '1._3'\n```\n\n## Operators\n\n- Equality: `eq(a: MaybeRational, b: MaybeRational): boolean`\n- Addition: `add(a: MaybeRational, b: MaybeRational): Rational`\n- Subtraction: `sub(a: MaybeRational, b: MaybeRational): Rational`\n- Negation: `neg(a: MaybeRational): Rational`\n- Multiplication: `mul(a: MaybeRational, b: MaybeRational): Rational`\n- Division: `div(a: MaybeRational, b: MaybeRational): Rational`\n- Inversion: `inv(a: MaybeRational): Rational`\n- Less than: `lt(a: MaybeRational, b: Rational): boolean`\n- Greater than: `gt(a: MaybeRational, b: MaybeRational): boolean`\n\n## Utils\n\n### coerceToRational\n\nValidates the argument and converts it to `Rational`\n\n```\ncoerceToRational(arg: MaybeRational): Rational\n```\n\n### isRational\n\nType guard. Check that the given argument is a valid `Rational`.\n\n```\nisRational(arg: unknown): arg is Rational\n```\n\n### rationalToNumber\n\nConverts a `Rational` to a number. The `numDecimals` defaults to 16.\n\n```\nrationalToNumber(arg: Rational, numDecimals?: number): number\n```\n\n## License\n\n[MIT](https://fibo.github.io/mit-license)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffibo%2Farithmetica","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffibo%2Farithmetica","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffibo%2Farithmetica/lists"}