{"id":20644550,"url":"https://github.com/dreampast/ulbn","last_synced_at":"2025-10-12T13:50:54.050Z","repository":{"id":258259335,"uuid":"871454259","full_name":"DreamPast/ulbn","owner":"DreamPast","description":"High-precision Number Library","archived":false,"fork":false,"pushed_at":"2025-03-26T04:47:59.000Z","size":1856,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-26T05:28:41.692Z","etag":null,"topics":["c","high-precision","high-precision-calculator","math"],"latest_commit_sha":null,"homepage":"","language":"C","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/DreamPast.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":"2024-10-12T02:41:22.000Z","updated_at":"2025-03-26T04:48:02.000Z","dependencies_parsed_at":"2024-11-07T06:26:06.860Z","dependency_job_id":"cd4f9407-72ef-467c-8621-fb37121c03fd","html_url":"https://github.com/DreamPast/ulbn","commit_stats":null,"previous_names":["dreampast/ulbn"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/DreamPast/ulbn","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DreamPast%2Fulbn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DreamPast%2Fulbn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DreamPast%2Fulbn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DreamPast%2Fulbn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DreamPast","download_url":"https://codeload.github.com/DreamPast/ulbn/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DreamPast%2Fulbn/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279011461,"owners_count":26084947,"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-10-12T02:00:06.719Z","response_time":53,"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":["c","high-precision","high-precision-calculator","math"],"created_at":"2024-11-16T16:16:46.676Z","updated_at":"2025-10-12T13:50:54.029Z","avatar_url":"https://github.com/DreamPast.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ulbn: High-precision Number Library\r\n\r\n[English](./README.md) [简体中文](./README_zh_CN.md)\r\n\r\n## Features\r\n\r\n- C89/C++98 compatible (optional C++20 headers available)\r\n- Minimal hardware assumptions\r\n- Avoids most UB (Undefined Behavior)\r\n- Strict boundary checks\r\n- Custom memory allocator support\r\n- Almost all functions reach time complexity of O(n*log(n))\r\n- No external dependencies\r\n\r\n## Requirements\r\n\r\nNo external dependencies needed.\r\n\r\n### ulbn.h/ulbn.c\r\n\r\nMinimum C89/C++98, with macros to suggest optimizations for some code.\r\n\r\nHardware Assumptions:\r\n\r\n- Requires `sizeof(ulbn_limb_t)` or `CHAR_BIT` to be even\r\n- Integer division must truncate toward zero (guaranteed since C99/C++98, implementation-defined otherwise)\r\n\r\n### ulbn.hpp\r\n\r\nRequires the following C++20 features:\r\n\r\n- Concepts and constranints\r\n- Three-way comparison\r\n- std::endian\r\n- std::span\r\n- std::format (optional)\r\n\r\nAccording to [cppreference](https://en.cppreference.com/), the common minimum compiler requirements is:\r\n- GCC 10 (May, 7, 2020)\r\n- Clang 10 (March, 24, 2020)\r\n- MSVC 19.26 (May, 19, 2020)\r\n\r\n### test\r\n\r\nRequires the following assumptions for modern platforms:\r\n\r\n- Signed integers are stored in two's complement form\r\n- `float` has 23 bits of precision (IEEE754)\r\n- `double` has 52 bits of precision (IEEE754)\r\n- `char` is 8-bits, and use ASCII\r\n- `int64_t` exists\r\n- The platform is little-endian or big-endian\r\n- \\\u003cbit\\\u003e\r\n- std::format (optional)\r\n\r\n## How to use\r\n\r\n### ulbn.h\r\n\r\nAdd \"ulbn.h\" and \"ulbn.c\" to your project.\r\n\r\n```c\r\n#include \"ulbn.h\"\r\n#include \u003cstdio.h\u003e\r\n\r\nint main(void) {\r\n  const ulbn_alloc_t* alloc = ulbn_default_alloc(); /* get default allocator */\r\n  ulbi_t ro, ao, bo;\r\n  int err;\r\n\r\n  /* initialize library */\r\n  ulbn_startup(); \r\n  /* first, we must initialize them */\r\n  ulbi_init(\u0026ro);\r\n  ulbi_init(\u0026ao);\r\n  ulbi_init(\u0026bo);\r\n\r\n\r\n  ulbi_set_slimb(\u0026ao, 99);              /* set ao = 99, `ulbi_set_slimb` doesn't make errors */\r\n  ulbi_set_slimb(\u0026bo, 99);              /* set bo = 99, `ulbi_set_slimb` doesn't make errors */\r\n  err = ulbi_add(alloc, \u0026ro, \u0026ao, \u0026bo); /* ro = ao + bo */\r\n  if(err) {\r\n    fprintf(stderr, \"error: %d\\n\", err);\r\n    return 1;\r\n  }\r\n  ulbi_print(alloc, stdout, \u0026ro, 10); /* print ro */\r\n  putchar('\\n');\r\n\r\n\r\n  err = ulbi_add_slimb(alloc, \u0026ro, \u0026ao, 99); /* some functions have a simpler version */\r\n  if(err) {\r\n    fprintf(stderr, \"error: %d\\n\", err);\r\n    return 1;\r\n  }\r\n  ulbi_print(alloc, stdout, \u0026ro, 10); /* print ro */\r\n  putchar('\\n');\r\n\r\n\r\n  err = ulbi_pow(alloc, \u0026ro, \u0026ao, \u0026bo); /* we can try larger number */\r\n  if(err) {\r\n    fprintf(stderr, \"error: %d\\n\", err);\r\n    return 1;\r\n  }\r\n  ulbi_print(alloc, stdout, \u0026ro, 10); /* print ro */\r\n  putchar('\\n');\r\n\r\n\r\n  /* finally, don't forget to deinitialize them */\r\n  ulbi_deinit(alloc, \u0026ro);\r\n  ulbi_deinit(alloc, \u0026ao);\r\n  ulbi_deinit(alloc, \u0026bo);\r\n\r\n  return 0;\r\n}\r\n\r\n#include \"ulbn.c\" /* we can include source code directly */\r\n\r\n```\r\n\r\n### ulbn.hpp\r\n\r\nAdd \"ulbn.hpp\", \"ulbn.h\" and \"ulbn.c\" to your project, and make sure your compiler support C++20.\r\n\r\n```cpp\r\n#include \"ulbn.hpp\"\r\n#include \u003ciostream\u003e\r\n\r\nint main() {\r\n  // In C++, we don't need to explicitly manage memory and check errors.\r\n  // With the help of operator overloading, we can use high precision more conveniently.\r\n  using ul::bn::BigInt;\r\n  BigInt ro, ao, bo;\r\n\r\n  ao = 99;\r\n  bo = 99;\r\n  ro = ao + bo;\r\n  std::cout \u003c\u003c ro \u003c\u003c '\\n';\r\n\r\n  ro = ao + 99;\r\n  std::cout \u003c\u003c ro \u003c\u003c '\\n';\r\n\r\n  ro = ao.pow(bo);\r\n  std::cout \u003c\u003c ro \u003c\u003c '\\n';\r\n\r\n  return 0;\r\n}\r\n\r\n#include \"ulbn.c\" // we can include source code directly\r\n\r\n```\r\n\r\n## Roadmap\r\n\r\n- [ ] High-precision integers\r\n  - [x] Arithmetic\r\n    - [x] Faster multiplicatin\r\n      - [x] Karatsuba algorithm (Toom-2)\r\n      - [x] Toom-3 algorithm\r\n      - [x] Toom-4 algorithm\r\n      - [x] FFT\r\n    - [x] Faster base conversion\r\n      - [x] Faster input\r\n      - [x] Faster output\r\n  - [x] Comparison\r\n  - [x] Bitwise Operation\r\n  - [x] Root\r\n  - [ ] Number theory functions\r\n    - [x] GCD/LCM\r\n    - [x] Extended GCD\r\n    - [ ] Prime number determination\r\n    - [ ] Prime number search\r\n    - [ ] Factorization\r\n- [ ] High-precision fractions\r\n- [ ] High-precision floating point number\r\n- [ ] High-precision decimal floating point number","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdreampast%2Fulbn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdreampast%2Fulbn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdreampast%2Fulbn/lists"}