{"id":21585943,"url":"https://github.com/magiclen/node-int64","last_synced_at":"2026-03-16T21:33:02.146Z","repository":{"id":57275027,"uuid":"109020959","full_name":"magiclen/node-int64","owner":"magiclen","description":"Use N-API to compute 64 bits integers.","archived":false,"fork":false,"pushed_at":"2024-11-26T17:21:51.000Z","size":333,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-23T04:32:01.170Z","etag":null,"topics":["int64","nodejs","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/magiclen.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":"2017-10-31T16:12:21.000Z","updated_at":"2024-10-22T03:51:18.000Z","dependencies_parsed_at":"2025-04-10T20:14:53.738Z","dependency_job_id":"59b11ad8-6d0c-4313-8b72-c3d329f8aa0e","html_url":"https://github.com/magiclen/node-int64","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"purl":"pkg:github/magiclen/node-int64","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magiclen%2Fnode-int64","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magiclen%2Fnode-int64/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magiclen%2Fnode-int64/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magiclen%2Fnode-int64/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/magiclen","download_url":"https://codeload.github.com/magiclen/node-int64/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magiclen%2Fnode-int64/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270892208,"owners_count":24663543,"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-17T02:00:09.016Z","response_time":129,"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":["int64","nodejs","rust"],"created_at":"2024-11-24T15:12:13.687Z","updated_at":"2026-03-16T21:32:57.118Z","avatar_url":"https://github.com/magiclen.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"Int64\n==========\n\n[![CI](https://github.com/magiclen/node-int64/actions/workflows/ci.yml/badge.svg)](https://github.com/magiclen/node-int64/actions/workflows/ci.yml)\n\nUse Rust to compute 64-bit signed integers.\n\nYou need to set up the Rust development environment: [rustup](https://rustup.rs/)\n\n## Usage\n\nFirst of all, an int64(long) value can be represented by\n\n1. An Int64 object (instance).\n1. A 53-bit integer number.\n1. A string of a decimal number.\n1. A string of a hexadecimal number, starting with `0x`.\n1. A string of an octal number, starting with `0o`.\n1. A string of a binary number, starting with `0b`.\n1. A buffer with 8 bytes\n\n### Static\n\nStatic funtions are used for quickly getting the final result as a JavaScript number. If you have several 64-bit integer computations to be done, it is better to use class methods instead.\n\nA JavaScript number can safely represent only from `-(2^53 - 1)` to `2^53 - 1`, and this library does not allow you to convert an unsafe-ranged integer to a JavaScript number.\n\n#### Random\n\n```typescript\nimport { random } from \"int64-napi\";\n\nconst n = random(9876543210, \"12345678901234\"); // 5724595911391\n```\n\n#### Add\n\n```typescript\nimport { add } from \"int64-napi\";\n\nconst n = add(\"0x0000000000000001\", 0x00000002); // 1 + 2 = 3\n```\n\n#### Subtract\n\n```typescript\nimport { subtract } from \"int64-napi\";\n\nconst n = subtract(1, 2); // 1 - 2 = -1\n```\n\n#### multiply\n\n```typescript\nimport { multiply } from \"int64-napi\";\n\nconst n = multiply(2, 6); // 2 * 6 = 12\n```\n\n#### divide\n\n```typescript\nimport { divide } from \"int64-napi\";\n\nconst n = divide(6, 4); // 6 / 4 = 1\n```\n\n#### mod\n\n```typescript\nimport { mod } from \"int64-napi\";\n\nconst n = mod(6, 4); // 6 % 4 = 2\n```\n\n#### shiftLeft\n\n```typescript\nimport { shiftLeft } from \"int64-napi\";\n\nconst n = shiftLeft(0b00101, 2); // 0b000101 \u003c\u003c 2 = 0b010100\n```\n\n#### shiftRight\n\n```typescript\nimport { shiftRight } from \"int64-napi\";\n\nconst n1 = shiftRight(0b0101, 2); // 0b0101 \u003e\u003e 2 = 0b0001\nconst n2 = shiftRight(0b0110, 1); // 0b0110 \u003e\u003e 1 = 0b0011\nconst n3 = shiftRight(\"0b1111111111111111111111111111111111111111111111111111111111111011\", 1); // 0b1111111111111111111111111111111111111111111111111111111111111011 \u003e\u003e 1 = 0b1111111111111111111111111111111111111111111111111111111111111101\n```\n\n#### shiftRightUnsigned\n\n```typescript\nimport { shiftRightUnsigned } from \"int64-napi\";\n\nconst n = shiftRightUnsigned(\"0b1111111111111111111111111111111111111111111111111111111111111011\", 32); // 0b1111111111111111111111111111111111111111111111111111111111111011 \u003e\u003e\u003e 32 = 0b0000000000000000000000000000000011111111111111111111111111111111\n```\n\n#### rotateRight\n\n```typescript\nimport { rotateRight } from \"int64-napi\";\n\nconst n = rotateRight(\"0x0000000080000100\", 20); // 0x0010000000000800\n```\n\n#### rotateLeft\n\n```typescript\nimport { rotateLeft } from \"int64-napi\";\n\nconst n = rotateLeft(\"0x0010000000000800\", 20); // 0x0000000080000100\n```\n\n#### and\n\n```typescript\nimport { and } from \"int64-napi\";\n\nconst n = and(\"0x000000000000FFFF\", \"0x0123456789ABCDEF\"); // 0x000000000000CDEF\n```\n\n#### or\n\n```typescript\nimport { or } from \"int64-napi\";\n\nconst n = or(\"0x0000FFFF0000FFFF\", \"0xFFFFFFFFFFFF0000\"); // 0xFFFFFFFFFFFFFFFF\n```\n\n#### xor\n\n```typescript\nimport { xor } from \"int64-napi\";\n\nconst n = xor(\"0x0000FFFF0000FFFF\", \"0xFFFFFFFFFFFF0000\"); // 0xFFFF0000FFFFFFFF\n```\n\n#### nand\n\n```typescript\nimport { nand } from \"int64-napi\";\n\nconst n = nand(\"0x000000000000FFFF\", \"0x0123456789ABCDEF\"); // 0xFFFFFFFFFFFF3210\n```\n\n#### nor\n\n```typescript\nimport { nor } from \"int64-napi\";\n\nconst n = nor(\"0x0000FFFF0000FFFF\", \"0xFFFFFFFFFFFF0000\"); // 0x0000000000000000\n```\n\n#### xnor\n\n```typescript\nimport { xnor } from \"int64-napi\";\n\nconst n = xnor(\"0x0000FFFF0000FFFF\", \"0xFFFFFFFFFFFF0000\"); // 0x0000FFFF00000000\n```\n\n#### not\n\n```typescript\nimport { nor } from \"int64-napi\";\n\nconst n = nor(\"0x0000FFFF0000FFFF\", \"0xFFFFFFFFFFFF0000\"); // 0x0000000000000000\n```\n\n#### eq (Equal)\n\n```typescript\nimport { eq } from \"int64-napi\";\n\nconst n = eq(\"0x0000FFFF0000FFFF\", \"281470681808895\"); // true\n```\n\n#### ne (Not Equal)\n\n```typescript\nimport { ne } from \"int64-napi\";\n\nconst n = ne(\"0x0000FFFF0000FFFF\", \"0x0000FFFF00000000\"); // true\n```\n\n#### gt (Greater Than)\n\n```typescript\nimport { gt } from \"int64-napi\";\n\nconst n = gt(\"0x0000FFFF0000FFFF\", \"0x0000FFFF00000000\"); // true\n```\n\n#### gte (Greater Than or Equal)\n\n```typescript\nimport { gte } from \"int64-napi\";\n\nconst n = gte(\"0x0000FFFF0000FFFF\", \"0x0000FFFF00000000\"); // true\n```\n\n#### lt (Less Than)\n\n```typescript\nimport { lt } from \"int64-napi\";\n\nconst n = lt(\"0x0000FFFF0000FFFF\", \"0x0000FFFF0000FFFF\"); // false\n```\n\n#### lte (Less Than or Equal)\n\n```typescript\nimport { lte } from \"int64-napi\";\n\nconst n = lte(\"0x0000FFFF0000FFFF\", \"0x0000FFFF0000FFFF\"); // true\n```\n\n#### comp (Compare)\n\nIf `a \u003c b`, returns `-1`.\n\nIf `a === b`, returns `0`.\n\nIf `a \u003e b`, returns `1`.\n\n```typescript\nimport { comp } from \"int64-napi\";\n\nconst a = comp(\"0x0000FFFF0000FFFF\", \"0x0000FFFF0000FFFF\"); // 0\nconst b = comp(\"0x0000FFFF0000FFFF\", \"0x0000FFFF00000000\"); // 1\nconst c = comp(\"0x0000FFFF00000000\", \"0x0000FFFF0000FFFF\"); // -1\n```\n\n### Instance / Object\n\n#### Create an Instance\n\n```typescript\nimport { Int64 } from \"int64-napi\";\n\nconst i64 = new Int64(1);\n```\n\n#### Methods\n\n`Int64` instance has methods which are corresponding to static functions. `Int64` instances are mutable and reusable, which means operations may modify its value.\n\n```typescript\nimport { Int64 } from \"int64-napi\";\n\nconst i64 = new Int64(1);\nconst n1 = i64.add(1).multiply(3).subtract(3).divide(3).toDecimal(); // \"1\"\n\ni64.set(\"0xFFFF000000000000\");\nconst n2 = i64.shiftLeft(8).shiftRight(56).toHex(true); // \"0xffffffffffffffff\"\n\ni64.set(\"0xFFFF000000000000\");\nconst n3 = i64.shiftLeft(8).shiftRightUnsigned(56).toHex(true); // \"0x00000000000000ff\"\n\ni64.set(\"0x000000010001\");\nconst n4 = i64.rotateRight(8).toHex(true); // \"0x0100000000000100\"\n\ni64.set(\"0x0000FFFFFFFF0000\");\nconst n51 = i64.toHex(true); // \"0x0000ffffffff0000\"\nconst n52 = i64.toHex(); // \"ffffffff0000\"\nconst n53 = i64.toDecimal() + 1; // \"2814749766451201\"\nconst n54 = i64.toNumber() + 1; // 281474976645121\n```\n\nTo clone an `Int64` instance.\n\n```typescript\nconst i64_2 = i64.clone();\n```\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmagiclen%2Fnode-int64","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmagiclen%2Fnode-int64","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmagiclen%2Fnode-int64/lists"}