{"id":49537439,"url":"https://github.com/wubingzheng/decimax","last_synced_at":"2026-05-02T12:05:01.344Z","repository":{"id":347797647,"uuid":"1188799937","full_name":"WuBingzheng/decimax","owner":"WuBingzheng","description":"Fast decimal types.","archived":false,"fork":false,"pushed_at":"2026-05-01T10:03:41.000Z","size":153,"stargazers_count":19,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-01T11:16:04.026Z","etag":null,"topics":["decimal","finance","mathematics"],"latest_commit_sha":null,"homepage":"https://docs.rs/lean-decimal/","language":"Rust","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/WuBingzheng.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-22T15:50:05.000Z","updated_at":"2026-05-01T09:47:13.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/WuBingzheng/decimax","commit_stats":null,"previous_names":["wubingzheng/lean-decimal","wubingzheng/decimax"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/WuBingzheng/decimax","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WuBingzheng%2Fdecimax","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WuBingzheng%2Fdecimax/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WuBingzheng%2Fdecimax/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WuBingzheng%2Fdecimax/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WuBingzheng","download_url":"https://codeload.github.com/WuBingzheng/decimax/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WuBingzheng%2Fdecimax/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32533353,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-02T11:28:32.350Z","status":"ssl_error","status_checked_at":"2026-05-02T11:27:30.140Z","response_time":132,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["decimal","finance","mathematics"],"created_at":"2026-05-02T12:04:59.355Z","updated_at":"2026-05-02T12:05:01.339Z","avatar_url":"https://github.com/WuBingzheng.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"Fast, fixed-size, floating-point decimal types.\n\nThis crate represents decimals accurately by scaling integer in base-10.\nSo there is no round-off error like 0.1 + 0.2 != 0.3.\n\nThere are kinds of ways to represent decimals, each with its own focus.\nThis crate is same kind to the most popular [`rust_decimal`](https://docs.rs/rust_decimal),\nbut *better*.\n\n\n# Compare with `rust_decimal`\n\nThis crate has these advantages:\n\n- Much faster. This crate is 2X ~ 6X faster than `rust_decimal` at `+`, `-`\nand `*` operations. While the `/` is complex, with both faster and slower\ncases. A typical comparison is shown in below chart. See\nthe [benchmark](https://github.com/WuBingzheng/decimax/blob/v0.2.0/benches/README.md)\nfor details.\n\n![Benchmark result](https://raw.githubusercontent.com/WuBingzheng/decimax/refs/tags/v0.2.0/benches/charts/mul-amd.svg)\n\n- More significant digits and fraction digits. All bits of the underlying\ninteger are used. No waste. For example the 128-bit signed decimal type\n[`Dec128`] has 122 bits for mantissa (about 36 decimal significant digits),\n5 bits for scale (at most 31 fraction digits), and 1 bit for sign. While\n`rust_decimal` has 96 bits for mantissa (about 28 digits) and at most\n28 fraction digits.\n\n- More types. It provides [6 types](#types) by now. Long and short (128/64/32-bit),\nsigned and unsigned.\n\n\n# How is it made faster?\n\nIn fact, there is no black magic in this crate (except for a fast division\nalgorithm which is used in just a few cases). I suspect the performance gain\nisn’t so much because this crate is fast, but because `rust_decimal` is slow.\n\nIn this crate, the decimal is defined as a single integer. Take the 128-bit type\nas example:\n\n```text\n+-+-----+-------------------------------+\n|S|scale|  mantissa                     |\n+-+-----+-------------------------------+\n```\n\nThe sign(`S`), scale, and mantissa occupy 1, 5, and 122 bits respectively.\nThe mantissa is computed as one single `u128` integer for each operation.\n\nIn contrast, the definition in `rust_decimal` is as follows:\n\n```text\n+---------+---------+---------+---------+\n| flags   | high    | mid     | low     |\n+---------+---------+---------+---------+\n```\n\nThe mantissa consists of three `u32` components, and each operation requires\nprocessing these three `u32` values in turn. Additionally, `rust_decimal`\nchecks whether the two operands are small(32 bit), medium(64 bit), or\nlarge(96 bit), and uses different computation processes accordingly.\nThese conditional checks themselves, along with the complex logic, may\nslow down the arithmetic operations.\n\nYou’ll get my point as long as you take a quick look at the code of the\naddition implementation\n[of this crate](https://docs.rs/crate/decimax/0.2.0/source/src/ops.rs#32)\nand [of rust_decimal](https://docs.rs/crate/rust_decimal/1.41.0/source/src/ops/add.rs).\n\nIn [`rust_decimal`'s documentation](https://docs.rs/rust_decimal/1.41.0/rust_decimal/#comparison-to-other-decimal-implementations),\nit's said that:\n\n\u003e  This structure allows us to make use of algorithmic optimizations to implement\n\u003e  basic arithmetic; ultimately this gives us the ability to squeeze out performance\n\u003e  and make it one of the fastest implementations available.\n\nI don't quite understand this sentence. I have to guess that it was developed\nbefore Rust's `u128` type was stabilized, when only `u64` or `u32` could be used.\n\nI’m not a performance expert, so the above is just my speculation. However,\nthe [benchmark results](https://github.com/WuBingzheng/decimax/blob/v0.2.0/benches/README.md)\nare objective. Please check it out and run it yourself.\n\n\n# Usage\n\n```rust\n// We take the 128-bit type as example.\nuse decimax::{Dec128, UDec32};\nuse core::str::FromStr;\n\n// Construct from integer and string, while the float is in process.\nlet a = Dec128::from(123);\nlet b = Dec128::from_str(\"123.456\").unwrap();\n\n// Construct from mantissa and scale.\nlet b2 = Dec128::from_parts(123456, 3);\nassert_eq!(b, b2);\n\n// Addition and substraction operate with same type only.\nassert_eq!(a + b, Dec128::from_parts(246456, 3)); // 123 + 123.456 = 246.456\n\n// Multiplication and division can operate with short integers and decimals too.\nlet p = Dec128::from_parts(246912, 3); // 123.456 * 2 = 246.912\nassert_eq!(b * 2, p); // by integer\nassert_eq!(b * UDec32::from_parts(2, 0), p); // by new unsigned decimal type\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwubingzheng%2Fdecimax","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwubingzheng%2Fdecimax","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwubingzheng%2Fdecimax/lists"}