{"id":23527235,"url":"https://github.com/Koishi-Satori/EirinFixed","last_synced_at":"2025-10-31T18:30:37.687Z","repository":{"id":269381279,"uuid":"907207242","full_name":"Koishi-Satori/fixed32","owner":"Koishi-Satori","description":"fixed point number library","archived":false,"fork":false,"pushed_at":"2025-01-07T02:23:16.000Z","size":54,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-07T03:34:36.901Z","etag":null,"topics":["cplusplus-20","fixed-point","library","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/Koishi-Satori.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-12-23T04:33:25.000Z","updated_at":"2025-01-07T02:23:19.000Z","dependencies_parsed_at":"2025-01-07T22:18:07.539Z","dependency_job_id":null,"html_url":"https://github.com/Koishi-Satori/fixed32","commit_stats":null,"previous_names":["koishi-satori/fixed32"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Koishi-Satori%2Ffixed32","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Koishi-Satori%2Ffixed32/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Koishi-Satori%2Ffixed32/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Koishi-Satori%2Ffixed32/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Koishi-Satori","download_url":"https://codeload.github.com/Koishi-Satori/fixed32/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239222724,"owners_count":19602667,"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":["cplusplus-20","fixed-point","library","math"],"created_at":"2024-12-25T20:13:03.393Z","updated_at":"2025-10-31T18:30:37.632Z","avatar_url":"https://github.com/Koishi-Satori.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fixed32\n\nA flexible and high-performance C++ fixed point number library, provides fixed point template class, high precision mathematical operations and basic input and output functions.\nThe output functions support the formatter provided by [Papilio Charontis](https://github.com/HenryAWE/PapilioCharontis).\n\nIt also provides a pre-defined 32bit-width fixed point, with 16bit precision(```fixed32```).\nThe fixed points require same calculation result in different platforms, devices, operator systems and compilers, and this library fulfills this requirement.\n\n\n### Create Fixed Point\n\nYou can create a fixed point number with integral or floating types using constructor and literals.\n\n- The literals now only provides for fixed32.\n- The way of constructing from floating type is not that recommended.\n    - Reason: Floating point error in different platforms, devices, operator systems and compilers.\n    - The fixed point needs to make sure same result in different situations.\n```c++\n#include \u003cfixed.hpp\u003e\n\nint main(int argc, char** argv)\n{\n    auto fp32_1 = fixed32(495);\n    auto fp32_2 = fixed32(114.514); // using \"114.5\"_f32 is better.\n    auto fp1 = fixed_num\u003cint32_t, int64_t, 20, false\u003e(5);\n    auto fp2 = fixed_num\u003cint32_t, int64_t, 20, false\u003e(5.14);\n    fp32_1 = 114_f32;\n    fp32_2 = 5.14_f32;\n    fp32_1 = \"49.5\"_f32;\n    fp32_2 = \"114.5\"_f32; // multi-platforms work-well!\n    fp32_2 = -\"114.5\"_f32;\n    fp32_2 = \"-114.5\"_f32; // both this and the one above are well.\n    return 0;\n}\n```\n\nYou can also create a fixed point from std::basic_istream or strings.\n\n- ```f32_from_cstring``` and ```fixed_from_cstring``` will return true on success.\n- the ```parse``` functions needs to pass the end of the string.\n    - it will stops when meeting the **first char** of the end string.\n    - for example, 114a.514a will only parse \"114\" part.\n\n```c++\n#include \u003cfixed.hpp\u003e\n\nint main(int argc, char** argv)\n{\n    fp1 = 0_f32;\n    fp2 = fixed_num\u003cint32_t, int64_t, 20, false\u003e(0);\n    f32_from_cstring(\"-114.514\", 8, fp1);\n    fixed_from_cstring(\"-5\", 2, fp2);\n    std::cin \u003e\u003e fp;\n    parse(\"114a.514a\", \"a\", fp);\n    return 0;\n}\n```\n\n### Fixed Point Output\n\nYou can use std::ostream or format functions provided by [Papilio Charontis](https://github.com/HenryAWE/PapilioCharontis).\n\n- When using Papilio Charontis, please **make sure** you have include the ```fixed_formatter.hpp``` header file.\n\n\n```c++\n#include \u003cfixed.hpp\u003e\n#include \u003cfixed_formatter.hpp\u003e\n\nint main(int argc, char** argv)\n{\n    std::cout \u003c\u003c \"114.5625\"_f32 \u003c\u003c std::endl;\n    std::cout \u003c\u003c \"-114.5625\"_f32 \u003c\u003c std::endl;\n    papilio::println(\"{:s}\", 114.5625_f32);\n    papilio::println(\"{:i}\", 114.5625_f32);\n    papilio::println(\"{:f}\", 114.5625_f32);\n    return 0;\n}\n```\n\n### From Internal Value\n\n- **NOTE: this is not recommended, UNLESS you know what you're doing.**\n\n```c++\n#include \u003cfixed.hpp\u003e\n\nint main(int argc, char** argv)\n{\n    auto fp = fixed32::from_inner_value(7504789);\n    auto log2_10 = fixed32::template from_fixed_num_value\u003c60\u003e(0x35269E12F346E200ll);\n    return 0;\n}\n```\n\n### Fixed Operator Functions\n\nYou can convert fixed point to integral or floating types.\n\n```c++\n#include \u003cfixed.hpp\u003e\n\n(int) \"114.5\"_f32;\n(float) \"114.5\"_f32;\n```\n\nYou can perform quadratic operations and module between fixed and fixed, fixed and integral, or integral and fixed.\nThe output will always be fixed point.\n\n```c++\n#include \u003cfixed.hpp\u003e\n\nfp1 = \"114.5\"_f32;\nfp2 = \"514\"_f32;\nfp1 + fp2;\nfp1 + 100;\n100 + fp2;\nfp1 *= 2;\nfp1 /= fp2;\n```\n\nThe compare functions are just like normal compare.\n\n### Fixed Mathematical Functions\n\nProvides high precision and fast pure c++ implemention.\n\nThe pre-defined math constants are defined in the fixed point number class.\n\nReferences:\n- Trigonometric Functions: [Efficient Approximations for the Arctangent Function](https://ieeexplore.ieee.org/document/1628884)\n- Square Root: [Fixed point sqrt](https://groups.google.com/g/comp.lang.c/c/IpwKbw0MAxw)\n- Binary Logarithm: [A Fast Binary Logarithm Algorithm](http://www.claysturner.com/dsp/BinaryLogarithm.pdf)\n\nSupported functions:\n- rounding functions\n    - ceil/floor\n    - trunc\n    - round\n- abs\n- min/max\n- sqrt\n- trigonometric functions\n    - sin/cos/tan\n    - asin/acos/atan\n- cbrt\n- log2/log/log10\n- pow/exp\n\n### Supported Compilers\n\nRequires at least C++20.\n\n- MSVC 19.3+ (Visual Studio 2022)\n- GCC 12+\n- Clang 15+ with libc++\n- Clang 16+ with libstdc++\n\n## License\n[MIT](LICENSE) License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKoishi-Satori%2FEirinFixed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FKoishi-Satori%2FEirinFixed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKoishi-Satori%2FEirinFixed/lists"}