{"id":26105290,"url":"https://github.com/osofem/bigarith.js","last_synced_at":"2025-08-01T06:18:33.974Z","repository":{"id":57189614,"uuid":"90597419","full_name":"osofem/bigarith.js","owner":"osofem","description":"Do very large math to precision!","archived":false,"fork":false,"pushed_at":"2017-08-16T09:51:16.000Z","size":247,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-24T13:02:42.921Z","etag":null,"topics":["arbitrary-precision","bigmath","bignumber","javascript","math"],"latest_commit_sha":null,"homepage":"https://osofem.github.io/bigarith.js/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/osofem.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}},"created_at":"2017-05-08T07:11:51.000Z","updated_at":"2020-12-19T18:13:33.000Z","dependencies_parsed_at":"2022-09-15T06:51:34.528Z","dependency_job_id":null,"html_url":"https://github.com/osofem/bigarith.js","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/osofem/bigarith.js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osofem%2Fbigarith.js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osofem%2Fbigarith.js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osofem%2Fbigarith.js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osofem%2Fbigarith.js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/osofem","download_url":"https://codeload.github.com/osofem/bigarith.js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osofem%2Fbigarith.js/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268178012,"owners_count":24208428,"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","bigmath","bignumber","javascript","math"],"created_at":"2025-03-09T21:04:07.266Z","updated_at":"2025-08-01T06:18:33.928Z","avatar_url":"https://github.com/osofem.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Welcome to bigarith.js\r\n[![Join the chat at https://gitter.im/BigArith-js/Lobby](https://badges.gitter.im/BigArith-js/Lobby.svg)](https://gitter.im/BigArith-js/Lobby?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\r\n\r\n`bigarith.js` offers a way to handle **very large numbers** (be it integers, fractionals, strings of digits, english words) to precision. bigarith is from the words **big arith**metic.\r\n\r\n```javascript\r\nvar ba = new BigArith(\"two million three hundred and sixty nine point two five seven one nine\");\r\nconsole.log( ba.add(\"300164677834746574576636455846484578468383.968785364758348\").subtract(\"58967883445567247657787456634534546650.0955344465644497\").multiply(\"-323333256645735747677476657457673734399124.90745562122345555\").divide(\"0.009899667856554544334565487673234\").abs().square().toString());\r\n/* This outputs \r\n\"96074475586197577621365133601838365203080754085195939359953075396624558104713187059409912271015743874101504692641365467550955268112648730652787010947788963291422897835924.2697158811425922569339591402860355619971451186954192254552990138752891749629006917912953942976702570634093674662564598087492412925971450372323378467910693943693505333234015230699695868364256999174194600745045683291593833019710855049245471924913674245229558192580612054808910477322678828203196181992794776861557204199127862657871835998341406371689589320661826402247662519900739514364587371169640378081\" \r\nto the console */\r\n```\r\nCheck [here](https://github.com/osofem/bigarith.js/tree/master/documentation) for full documentation.\r\n\r\n### Chanelog for v0.0.8\r\n* Fixed a bug in div\r\n\r\nFull Changelog [here](https://github.com/osofem/bigarith.js/blob/master/CHANGELOG.md).\r\n\r\n### Install\r\nDepending on the environment in which bigarith.js will be used, it can be installed via:\r\n\r\nServer-side usage\r\n1. Installing on node.js\r\n\t```javascript\r\n\tnpm install bigarith.js\r\n\t```\r\n\r\nClient-side usage\r\n1. Including the library from the rawgit.com CDN.\u003cbr\u003e\r\n\tYou can do that by adding \u003ccode\u003e\u0026lt;script src=\u0026quot;https\u0026#58;\u0026#47;\u0026#47;cdn.rawgit.com/osofem/bigarith.js/\u0026lt;version tag\u0026gt;/bigarith.js\u0026quot;\u0026gt;\u0026lt;/script\u0026gt;\u003c/code\u003e to your code. Replace \u003ccode\u003e\u0026lt;version tag\u0026gt;\u003c/code\u003e with the version targeted e.g. `v1.0.0`. Check [versions](https://github.com/osofem/bigarith.js/tags) for the latest version (the latest version is always recommended).\r\n2. Downloading the source from GitHub.com\u003cbr\u003e\r\n\tYou can also download bigarith.js from [releases](https://github.com/osofem/bigarith.js/releases/) on github.com (the latest version is always recommended). Extract the files and include the bigarith.js file in your work.\r\n\r\nChoose the method that best suit your need.\r\n\r\n### Usage\r\n\r\n\u003e In the server-side, always add the `var BigArith = require('bigarith.js');` however every other thing remains the same in both server-side and client-side.\r\n\r\nCheck [documentation](https://github.com/osofem/bigarith.js/tree/master/documentation) for the full list of supported functions.\r\n\r\n#### Initialization\r\n`bigarith.js` can be initialized in six ways.\r\n\r\n##### 1. Initiating without any parameter or null\r\n###### Server-side\r\n```javascript\r\nvar BigArith = require('bigarith.js');\r\nvar ba = new BigArith(); //initialize ba to a BigArith object of value \"0\"\r\nvar ba = new BigArith(null); //initialize ba to a BigArith object of value \"0\"\r\n```\r\n\r\n###### Client-side\r\n```javascript\r\nvar ba = new BigArith(); //initialize ba to a BigArith object of value \"0\"\r\nvar ba = new BigArith(null); //initialize ba to a BigArith object of value \"0\"\r\n```\r\nThis simply initialize the variable `ba` to a `BigArith` object of value `\"0\"`.\r\n\r\n##### 2. Initiating with a number\r\n###### Server-side\r\n```javascript\r\nvar BigArith = require('bigarith.js');\r\nvar ba = new BigArith(12345); //initialize ba to a BigArith object of value \"12345\"\r\n```\r\n\r\n###### Client-side\r\n```javascript\r\nvar ba = new BigArith(12345); //initialize ba to a BigArith object of value \"12345\"\r\n```\r\nThe number must be between the `Number.MIN_SAFE_INTEGER` (-9007199254740991) and `Number.MAX_SAFE_INTEGER` (9007199254740991) limits else a `RangeError` will be thrown. \u003cem\u003ePlease note that only integers are recommended for this method\u003c/em\u003e because of the floating point precision _problem_ in JavaScript (which is one of the problems bigarith.js aim to solve). \r\n\r\nDoing `var ba = new BigArith(0.45);` might still be considered _\"safe\"_ but some could be tempted to do `var ba = new BigArith(0.1*0.2);`. As it is known `0.1*0.2` will not give `0.02` in JavaScript but rather `0.020000000000000004`. Therefore, it is better to avoid initializing fractional numbers this way.\r\n\r\n\u003e It is recommended fractional numbers are initialized with strings.\r\n\u003e See [here](#3-initiating-with-string).\r\n\r\n##### 3. \u003cspan id=\"#3-initiating-with-string\"\u003eInitiating with string\u003c/span\u003e\r\n###### Server-side\r\n```javascript\r\nvar BigArith = require('bigarith.js');\r\nvar ba = new BigArith(\"67876445565433556789877654567987457008645656765434567889086654234542126677.8977566766788767\"); //initialize ba to a BigArith object of value \"67876445565433556789877654567987457008645656765434567889086654234542126677.8977566766788767\"\r\nvar bb = new BigArith(\"\"); //initialize bb to a BigArith object of value \"0\"\r\nvar bc = new BigArith(\"-123\"); //initialize bc to a BigArith object of value \"-123\"\r\nvar bd = new BigArith(\"+123\"); //initialize bd to a BigArith object of value \"123\"\r\nvar be = new BigArith(\"123\"); //initialize be to a BigArith object of value \"123\"\r\n```\r\n\r\n###### Client-side\r\n```javascript\r\nvar ba = new BigArith(\"67876445565433556789877654567987457008645656765434567889086654234542126677.8977566766788767\"); //initialize ba to a BigArith object of value \"67876445565433556789877654567987457008645656765434567889086654234542126677.8977566766788767\"\r\nvar bb = new BigArith(\"\"); //initialize bb to a BigArith object of value \"0\"\r\nvar bc = new BigArith(\"-123\"); //initialize bc to a BigArith object of value \"-123\"\r\nvar bd = new BigArith(\"+123\"); //initialize bd to a BigArith object of value \"123\"\r\nvar be = new BigArith(\"123\"); //initialize be to a BigArith object of value \"123\"\r\n```\r\n`bigarith.js` accepts strings of digits. This can be of any length, can be negative, positive, integer, or fractional number. An empty string initializes to `\"0\"`. \r\nStrings that contains characters other than: digits `0` to `9`, `-` or `+` (at the start of the string), or `.` (appearing just once), will evaluate to `NaN`\r\n\r\n##### 4. Initiating with words\r\n###### Server-side\r\n```javascript\r\nvar BigArith = require('bigarith.js');\r\nvar ba = new BigArith(\"negative five million six hundred and thirty seven thousand eight hundred and sixty five point three two\"); //initialize ba to a BigArith object of value \"-5637865.32\"\r\nvar bb = new BigArith(\"positive three\"); //initialize bb to a BigArith object of value \"3\"\r\nvar bc = new BigArith(\"three\"); //initialize bc to a BigArith object of value \"3\"\r\nvar bd = new BigArith(\"point two three seven\"); //initialize bd to a BigArith object of value \"0.237\"\r\n```\r\n\r\n###### Client-side\r\n```javascript\r\nvar ba = new BigArith(\"negative five million six hundred and thirty seven thousand eight hundred and sixty five point three two\"); //initialize ba to a BigArith object of value \"-5637865.32\"\r\nvar bb = new BigArith(\"positive three\"); //initialize bb to a BigArith object of value \"3\"\r\nvar bc = new BigArith(\"three\"); //initialize bc to a BigArith object of value \"3\"\r\nvar bd = new BigArith(\"point two three seven\"); //initialize bd to a BigArith object of value \"0.237\"\r\n```\r\n`bigarith.js` accepts english words of up to (\u0026#177;1x10^1,005)-0.0000{insert 195 more zeroes}01 (i.e. nine hundred and ninety nine trecentretrigintillion point nine nine nine nine nine {insert 195 more \"nine\"'s}). That is 1,005 length of characteristic (parts before the decimal point) and 200 length of mantissa (parts after the decimal point). \r\n\r\n\u003e *This limit only applies to when initializing with words, [initializing with strings](#3-initiating-with-string) can be to any length. \r\n\r\nA negative number \u003cem\u003eshould\u003c/em\u003e start with the word `\"negative\"`, a positive number can start with the \"positive\" word but this can be outrightly omitted. The mantissa part \u003cem\u003eshould be spelt out\u003c/em\u003e after the word `point` or else the word will evaluate to `NaN`.\r\n\r\nThis is case insensitive and only [Short Scale](https://osofem.github.io/bigarith.js/documentation/short_scales.html) naming system is supported.\r\n\r\n```javascript\r\nvar ba = new BigArith(\"three point one two\"); // This evaluate to \"3.12\"\r\nvar bb = new BigArith(\"three point twelve\"); // This evaluate to NaN\r\n```\r\n##### 5. Initiating with a constant\r\n###### Server-side\r\n```javascript\r\nvar BigArith = require('bigarith.js');\r\nvar ba = new BigArith(\"PI\"); // this evaluate to \"3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196\"\r\n```\r\n\r\n###### Client-side\r\n```javascript\r\nvar ba = new BigArith(\"PI\"); // this evaluate to \"3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196\"\r\n```\r\n`bigarith.js` has a list of inbuilt constants which can be used for initialization. Check [here](https://osofem.github.io/bigarith.js/documentation/list_constants.html) for the updated list.\r\n\r\n##### 6. Initiating with a BigArith object\r\n###### Server-side\r\n```javascript\r\nvar BigArith = require('bigarith.js');\r\nvar ba = new BigArith(\"3\"); //initialize ba to a BigArith object of value \"3\"\r\nvar bb = new BigArith(ba); //initialize bb to the value of ba (i.e. \"3\")\r\n```\r\n\r\n###### Client-side\r\n```javascript\r\nvar ba = new BigArith(\"3\"); //initialize ba to a BigArith object of value \"3\"\r\nvar bb = new BigArith(ba); //initialize bb to the value of ba (i.e. \"3\")\r\n```\r\n\r\n### Functions\r\n#### \u003cspan id=\"tostring-method\"\u003etoString() method\u003c/span\u003e\r\nThe `toString()` method returns the value of the BigArith object as a strings of digits.\r\n\r\n```javascript\r\nvar ba = new BigArith(\"negative five million six hundred and thirty seven thousand eight hundred and sixty five point three two\");\r\nconsole.log(ba.toString());//this outputs \"-5637865.32\" to the console\r\n```\r\n\r\n#### valueOf() method\r\nThe `valueOf()` method returns the value of the BigArith object as a number.\r\n\r\n```javascript\r\nvar ba = new BigArith(\"negative five million six hundred and thirty seven thousand eight hundred and sixty five point three two\");\r\nconsole.log(ba.valueOf());//this outputs -5637865.32 to the console\r\n```\r\n\r\n\u003e NOTE: Use this function with caution as JavaScript numbers looses precision once it is greater than Number.MAX_SAFE_INTEGER or lesser than Number.MIN_SAFE_INTEGER and becomes \"Infinity\" when it is greater than Number.MAX_VALUE and \"-Infinity\" when it is less than Number.MIN_VALUE.\r\n\r\n```javascript\r\nvar ba = new BigArith(\"999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\");\r\nconsoole.log(ba.valueOf()); //this outputs Infinity\r\nconsoole.log(ba.toString()); //this outputs \"999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\"\r\n```\r\n\r\n#### toWords() method\r\nThe `toWords` method returns the value of the BigArith object in English words using the [Short Scale](https://osofem.github.io/bigarith.js/documentation/short_scales.html) naming system. If the length of the object's characteristic part (part before the decimal point) is greater than 1,005 or the length of the mantissa part (part after the decimal point) is greater than 200, a `RangeError` is thrown.\r\n\r\n\u003e *This limit only applies to the `toWords()` method function, [toString()](#tostring-method) outputs the value of the BigArith object to any lenth as a string of digits.*\r\n\r\n```javascript\r\nvar ba = new BigArith(1e3);\r\nconsole.log(ba.toWords());//this outputs \"one thousand\" to the console\r\n```\r\n\r\nSee also:\r\n1. [abs()](https://osofem.github.io/bigarith.js/documentation/abs.html)\r\n2. [add()](https://osofem.github.io/bigarith.js/documentation/add.html)\r\n3. [ceil()](https://osofem.github.io/bigarith.js/documentation/ceil.html)\r\n4. [compare()](https://osofem.github.io/bigarith.js/documentation/compare.html)\r\n5. [compareAbs()](https://osofem.github.io/bigarith.js/documentation/compareabs.html)\r\n6. [divide()](https://osofem.github.io/bigarith.js/documentation/divide.html)\r\n7. [floor()](https://osofem.github.io/bigarith.js/documentation/floor.html)\r\n8. [isEven()](https://osofem.github.io/bigarith.js/documentation/iseven.html)\r\n9. [isNegative()](https://osofem.github.io/bigarith.js/documentation/isnegative.html)\r\n10. [isOdd()](https://osofem.github.io/bigarith.js/documentation/isodd.html)\r\n11. [isPositive()](https://osofem.github.io/bigarith.js/documentation/ispositive.html)\r\n12. [max()](https://osofem.github.io/bigarith.js/documentation/max.html)\r\n13. [min()](https://osofem.github.io/bigarith.js/documentation/min.html)\r\n14. [modulus()](https://osofem.github.io/bigarith.js/documentation/modulus.html)\r\n15. [multiply()](https://osofem.github.io/bigarith.js/documentation/multiply.html)\r\n16. [random()](https://osofem.github.io/bigarith.js/documentation/random.html)\r\n17. [randomInt()](https://osofem.github.io/bigarith.js/documentation/randomint.html)\r\n18. [round()](https://osofem.github.io/bigarith.js/documentation/round.html)\r\n19. [square()](https://osofem.github.io/bigarith.js/documentation/square.html)\r\n20. [squareRoot()](https://osofem.github.io/bigarith.js/documentation/squareroot.html) [unstable]\r\n21. [subtract()](https://osofem.github.io/bigarith.js/documentation/subtract.html)\r\n22. [toFixed()](https://osofem.github.io/bigarith.js/documentation/tofixed.html)\r\n23. [toWords()](https://osofem.github.io/bigarith.js/documentation/towords.html)\r\n24. [toString()](https://osofem.github.io/bigarith.js/documentation/tostring.html)\r\n25. [valueOf()](https://osofem.github.io/bigarith.js/documentation/valueof.html)\r\n26. [truncate()](https://osofem.github.io/bigarith.js/documentation/truuncate.html)\r\n27. [negate()](https://osofem.github.io/bigarith.js/documentation/negate.html)\r\n28. [sin()](https://osofem.github.io/bigarith.js/documentation/sin.html) [unstable]\r\n29. [cos()](https://osofem.github.io/bigarith.js/documentation/cos.html) [unstable]\r\n30. [tan()](https://osofem.github.io/bigarith.js/documentation/tan.html) [unstable]\r\n\r\nFull documentation is [here](https://github.com/osofem/bigarith.js/tree/master/documentation).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fosofem%2Fbigarith.js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fosofem%2Fbigarith.js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fosofem%2Fbigarith.js/lists"}