{"id":22551825,"url":"https://github.com/munrocket/double-js","last_synced_at":"2025-04-05T12:08:04.700Z","repository":{"id":33592097,"uuid":"145023317","full_name":"munrocket/double-js","owner":"munrocket","description":":dancing_women: Double-double arithmetic in javascript. A floating point expansion with 31 accurate decimal digits.","archived":false,"fork":false,"pushed_at":"2024-12-12T15:32:52.000Z","size":697,"stargazers_count":117,"open_issues_count":13,"forks_count":10,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-12-18T03:35:46.484Z","etag":null,"topics":["bigfloat","double-double","doubledouble","float128","qd","quadruple"],"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/munrocket.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}},"created_at":"2018-08-16T18:08:58.000Z","updated_at":"2024-12-03T21:56:45.000Z","dependencies_parsed_at":"2023-09-26T15:48:59.683Z","dependency_job_id":"4471c746-4f44-4814-b7b5-bae650b4880b","html_url":"https://github.com/munrocket/double-js","commit_stats":{"total_commits":159,"total_committers":10,"mean_commits":15.9,"dds":0.5786163522012578,"last_synced_commit":"4513198b596b83542041a272383c61f625e340f9"},"previous_names":["munrocket/double-js","munrocket/double.js"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/munrocket%2Fdouble-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/munrocket%2Fdouble-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/munrocket%2Fdouble-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/munrocket%2Fdouble-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/munrocket","download_url":"https://codeload.github.com/munrocket/double-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247332612,"owners_count":20921853,"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","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":["bigfloat","double-double","doubledouble","float128","qd","quadruple"],"created_at":"2024-12-07T17:14:53.345Z","updated_at":"2025-04-05T12:08:04.677Z","avatar_url":"https://github.com/munrocket.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# double.js [![bundlephobia](https://badgen.net/bundlephobia/minzip/double.js)](https://bundlephobia.com/result?p=double.js) [![Codecov](https://img.shields.io/codecov/c/github/munrocket/double.js.svg)](https://codecov.io/gh/munrocket/double.js)\n\nFloating point expansion with 31 accurate decimal digits (106 bits), also known as double-double arithmetic or\nemulated float128. This library can be useful for fast calculation with extended precision. For example in orbital mechanics, computational geometry and numerically unstable algorithms such as high precision integration, differentiation, triangulation, raytracing on gpu, inversion of ill-conditioned matrix.\n\n### Algorithm\nNumber stored as unevaluated sum of two javascript float numbers and uses error-free arithmetic algorithms.\nThis brings accuracy and significant increase in performance in comparison to\ndigit-wise approach, because this float arithmetic is implemented in hardware. Note that there are no\ntheoretical limitations to javascript since it uses 64 bit IEEE 754 with round-to-nearest-even\nafter each operation. The only limitation that javasript not support FMA. GPU hardware sometimes not follow\nIEEE arithmetic and can produce artifacts, but CPU arithmetic is robust and browsers are well tested.\n\n### Benchmark\n![](https://i.imgur.com/dXeSYKO.png)\n\nYou can check [quality / performance](https://munrocket.github.io/double-js/test/bench/bench.html) and [correctness](https://munrocket.github.io/double-js/test/e2e.html) of double.js library in your browser.\n\n### Usage\nInclude double.js script to webpage or install npm package. Here some basic examples\n```javascript\n// example with ES6 modules, also you can use ES5\nimport { Double } from 'double.js';\n\n// '0.3' - '0.1' == 0.2\nconsole.log(new Double('0.3').sub(new Double('0.1')).toNumber());\n\n// L = sqrt(a^2 + 10)\nlet L = a.sqr().add(10).sqrt();\n\n// S(r) = 4/3 * PI * r^3\nconst S = (r) =\u003e new Double('4.1887902047863909846168578443726').mul(r.pown(3));\n\n// f'(x) = (f(x+h) - f(x)) / h;\nlet dF = (x) =\u003e F(x.add(h)).sub(F(x)).div(h);\n\n// |f'(x)| \u003c 1 ? print(x)\nif (dF(x).abs().lt(1)) { console.log(x.toExponential()); }\n```\nFurther API details you can find in [wiki](https://github.com/munrocket/double-js/wiki) page and check it in [sandbox](https://runkit.com/munrocket/double-js-example). Be careful when initializing a new floats, for example `new Double(0.1)` is ok for integer numbers, but you should use `new Double('0.1')` to get correct results for fractional numburs. All double-double arithmetic functions are accurate and tested, say me if you find something strange.\n\n### WebAssembly version\nI got x3 boost in Chrome, x3.5 in Safari and x7 in Firefox for mandelbrot set algo with hardcoded global variables. To get speed improvement with wasm, you need to write your entire algorithm with it, because Js\u003c-\u003eWasm interop is too heavy.\n\n### WebGL/WebGPU versions\nJust copy/paste the code with MIT copyright, here [shadertoy example](https://www.shadertoy.com/view/flyBWw).\n\n### Special thanks\nTo [Jeffrey Sarnoff](https://github.com/JeffreySarnoff) for help me with books and algorithms. [Sergey Yanovich](https://github.com/yanovich) for fixing issues with toExponential(). To [Max Graey](https://github.com/MaxGraey) for AssemblyScript remarks. To [Yaffle](https://github.com/Yaffle) for fixing benchmark.\n\n### References\n1. J.-M. Muller, etc. *Tight and rigourous error bounds for basic building blocks of double-word arithmetic.*, 2017. [[PDF](https://hal.archives-ouvertes.fr/hal-01351529v3/document)]\n2. J.-M. Muller, N. Brisebarre, F. deDinechin, etc. *Handbook of Floating-Point Arithmetic*, Chapter 14, 2010.\n3. David Monniaux *The pitfalls of verifying floating-point computations*, 2008 [[PDF](https://hal.archives-ouvertes.fr/hal-00128124/file/floating-point-article.pdf)]\n4. Yozo Hida, Xiaoye Li, David Bailey. *Algorithms for Quad-Double Precision Floating Point Arithmetic*, 2020. [[PDF](https://portal.nersc.gov/project/sparse/xiaoye-web/arith15.pdf)]\n5. Christoph Lauter *Basic building blocks for a triple-double intermediate format*, 2006. [[PDF](https://hal.inria.fr/inria-00070314/document)]\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmunrocket%2Fdouble-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmunrocket%2Fdouble-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmunrocket%2Fdouble-js/lists"}