{"id":16572640,"url":"https://github.com/lemire/jstypes","last_synced_at":"2025-10-29T02:30:17.580Z","repository":{"id":57126684,"uuid":"162766094","full_name":"lemire/jstypes","owner":"lemire","description":"Doing C-like arithmetic and logical operations in JavaScript (full 64-bit support)","archived":false,"fork":false,"pushed_at":"2018-12-22T02:09:07.000Z","size":139,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-01T21:11:09.685Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lemire.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-2.0.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-12-21T23:21:55.000Z","updated_at":"2021-11-09T17:55:46.000Z","dependencies_parsed_at":"2022-08-31T12:12:00.641Z","dependency_job_id":null,"html_url":"https://github.com/lemire/jstypes","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lemire%2Fjstypes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lemire%2Fjstypes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lemire%2Fjstypes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lemire%2Fjstypes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lemire","download_url":"https://codeload.github.com/lemire/jstypes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238758222,"owners_count":19525728,"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-11T21:28:09.726Z","updated_at":"2025-10-29T02:30:17.001Z","avatar_url":"https://github.com/lemire.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jstypes\n\nThe jstypes library uses WebAssembly to support C-like arithmetic and logical operations in JavaScript. The essential strategy is to represent all numbers as string representing 64-bit hexadecimal numbers (we call them \"hex64\"). Conceptually these strings represent the content of a 64-bit register. These strings can be added, multiplied and so forth, resulting in other similar (hex64) strings. We can also convert these hex64 strings to other representations like 32-bit signed integers of 8-bit unsigned integers, as a processor would. Thus we use strings between  \"0000000000000000\" and \"FFFFFFFFFFFFFFFF\" as inputs. Some instructions also expect a bit width parameter (out of 8, 16, 32, and 64). When specifying a bit width of 32, only the least significant 32 bits are processed.  Thus we use strings between  \"0000000000000000\" and \"FFFFFFFFFFFFFFFF\" as inputs. Some instructions also expect a bit width parameter (out of 8, 16, 32, and 64). When specifying a bit width of 32, only the least significant 32 bits are processed.\n\n\n\n## Example\n\nThe following JavaScript code\n\n```\n  console.log(\"FF000000000000 + 00111111111111 (32 bits) = \"\n   +jstypes.hex64_add(\"FF000000000000\",\"00111111111111\",32));\n\n  console.log(\"FF000000000000 * 00111111111111 (64 bits) = \"\n  +jstypes.hex64_multiply(\"FF000000000000\",\"00111111111111\",64));\n\n  console.log(\"FF000000000000 shifted by 35 bits in signed mode is = \"\n  +jstypes.hex64_shift_right_signed(\"FF00000000000000\",35, 64));\n```\nshould output...\n\n```\nFF000000000000 + 00111111111111 (32 bits) = 11111111\nFF000000000000 * 00111111111111 (64 bits) = FFEF000000000000\nFF000000000000 shifted by 35 bits in signed mode is = FFFFFFFFFFE00000\n```\n\nWe support the following functions:\n\n  - hex64_add\n  - hex64_subtract\n  - hex64_multiply\n  - hex64_to_double\n  - hex64_to_float\n  - double_to_hex64\n  - hex64_to_signed\n  - unsigned_to_hex64\n  - signed_to_hex64\n  - float_to_hex64\n  - hex64_or\n  - hex64_and\n  - hex64_andnot\n  - hex64_xor\n  - hex64_equal\n  - hex64_lessthan_signed\n  - hex64_greaterthan_signed\n  - hex64_negate\n  - hex64_not\n  - hex64_shift_left\n  - hex64_shift_right_signed\n\n## Working node instructions\n\nGo to a new directory and load the library:\n\n```\nnpm init\nnpm i @lemire/jstypes\n```\n\n\n\nCreate and run the following script (e.g., as test.js):\n\n```\nvar jstypes = require(\"@lemire/jstypes\")\n\n\njstypes.init().then(ready =\u003e {\n  console.log(\"FF000000000000 + 00111111111111 (32 bits) = \"\n   +jstypes.hex64_add(\"FF000000000000\",\"00111111111111\",32));\n\n  console.log(\"FF000000000000 * 00111111111111 (64 bits) = \"\n  +jstypes.hex64_multiply(\"FF000000000000\",\"00111111111111\",64));\n\n  console.log(\"FF000000000000 shifted by 35 bits in signed mode is = \"\n  +jstypes.hex64_shift_right_signed(\"FF00000000000000\",35, 64));\n\n}).\ncatch(error =\u003e {\n  console.log(error.message);\n});\n```\n\n## Todo and limitations\n\n- This code is largely untested.\n- It is unclear whether it works in a browser (only tested in node).\n- We do not support floating-point operations (but it is easily added).\n- It is unclear whether you can go from hex64 to float and back without error (you almost certainly can't).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flemire%2Fjstypes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flemire%2Fjstypes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flemire%2Fjstypes/lists"}