{"id":16178371,"url":"https://github.com/munrocket/proposal-math-float","last_synced_at":"2025-03-19T01:30:47.617Z","repository":{"id":49148976,"uuid":"321597813","full_name":"munrocket/proposal-math-float","owner":"munrocket","description":null,"archived":false,"fork":false,"pushed_at":"2021-09-14T14:46:10.000Z","size":38,"stargazers_count":6,"open_issues_count":3,"forks_count":1,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-03-17T01:35:09.004Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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}},"created_at":"2020-12-15T08:13:09.000Z","updated_at":"2024-11-20T08:54:58.000Z","dependencies_parsed_at":"2022-08-25T15:21:21.525Z","dependency_job_id":null,"html_url":"https://github.com/munrocket/proposal-math-float","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/munrocket%2Fproposal-math-float","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/munrocket%2Fproposal-math-float/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/munrocket%2Fproposal-math-float/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/munrocket%2Fproposal-math-float/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/munrocket","download_url":"https://codeload.github.com/munrocket/proposal-math-float/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244336111,"owners_count":20436770,"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":[],"created_at":"2024-10-10T05:13:37.161Z","updated_at":"2025-03-19T01:30:47.336Z","avatar_url":"https://github.com/munrocket.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# proposal-math-float\n\nJavaScript arithmetic is implemented in a non-standard way, compared to other languages.\nOver time, there was a demand for performance and precision but the language itself does not\ngive an opportunity for some effective algorithms. This proposal offers to add signbit, inverse square,\nldexp that multiplying by 2 raised to the exp power, frexp that decomposes given floating point\nvalue arg into a normalized fraction and an integral power of two, scalar FMA instruction that\nperforms multiplication-addition in one step with single rounding, successor/predecessor of\nfloating point number\n\n### Proposed syntax\n```js\nlet signbit = Math.signbit(x)\nlet invsqrt = Math.rsqrt(x);\nlet ldexp = Math.ldexp(x);\nlet frexp = Math.frexp(x);\nlet fma = Math.fma(x, y, z);\nlet successor = Math.nextUp(x);\nlet predecessor = Math.nextDown(x);\n```\n\n### Similar proposals\n- [proposal-math-extensions](https://github.com/rwaldron/proposal-math-extensions)\n- [proposal-math-signbit](https://github.com/tc39/proposal-Math.signbit)\n\n\n### Motivation to add this functions because they can be faster in native code\n- signbit() current polyfill to get sign bit is slower that it can be `(x = +x) == x \u0026\u0026 x == 0 ? 1 / x == -Infinity : x \u003c 0`\n- rsqrt() is used in computer graphics, we have Math.hypot(x, y) in JS but it's not inverted\n- ldexp() could be useful for multiplication optimization on 2**n (in Java it is called scalb())\n- frexp() could be useful for bit analysis inside float number and correct rounding\n- fma() very useful for optimizing multiplication in arbitrary precision floating point libraries\n- nextUp()/nextDown() basic blocks for floating-point computations with correct rounding\n\n### Pollyfills status\n| Function | Implementation                                                        |\n|----------|-----------------------------------------------------------------------|\n| signbit  | [core-js in npm](https://github.com/zloirock/core-js/blob/ce52fdc735c5c809c9e85b2072f92d41b5a3885a/tests/tests/esnext.math.signbit.js)|\n| rsqrt    | trivial                                                               |\n| ldexp    | [stdlib.js in npm](https://www.npmjs.com/package/math-float64-ldexp)  |\n| frexp    | [stdlib.js in npm](https://www.npmjs.com/package/math-float64-frexp)  |\n| fma      | without overflow for now                                              |\n| nextUp   | done and tested                                                       |\n| nextDown | done and tested                                                       |\n\n### Disclaimer\nThis proposal based on my R\u0026D projects ([1](https://github.com/munrocket/double.js),\n[2](https://github.com/munrocket/jampary)) with floating point numbers and created as alternative to\n[decimal-proposal](https://github.com/tc39/proposal-decimal). I feel frustrated that JS not added this\nbasic blocks 5 years ago and we at that point when something hardcore is computed not as fast as it could be.\nThere are two type of arbitrary precision floating point libraries: based on integers and based on floats.\nSince javascript don't have integers historically I found that solution based on floats much easier\nin implementation and equally good as solutions based on integer arithmetic, when it properly cooked.\ninvSqrt() / frexp() was added after inspiration with new WGSL specification, nextUp() / nextDown()\nexist in Java with same syntax, scalar fma() is the reason why this proposal was created.\n\n### Key algorithms for polyfill implementation\n1. Chris Lomont. _Fast inverse square root_\n2. Sylvie Boldo, Guillaume Melquiond. _Emulation of a FMA and correctly-rounded sums: proved algorithms using rounding to odd._\n3. Siegfried Rump, Paul Zimmermann, Sylvie Boldo, Guillaume Melquiond _Computing predecessor and successor in rounding to nearest_\n4. Masahide Kashiwagi _Emulation of Rounded Arithmetic in Rounding to Nearest_\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmunrocket%2Fproposal-math-float","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmunrocket%2Fproposal-math-float","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmunrocket%2Fproposal-math-float/lists"}