{"id":41940920,"url":"https://github.com/nordlow/gmp-d","last_synced_at":"2026-01-25T18:37:40.731Z","repository":{"id":49389289,"uuid":"78653379","full_name":"nordlow/gmp-d","owner":"nordlow","description":"D-language high-level wrapper for GNU MP (GMP) library","archived":false,"fork":false,"pushed_at":"2025-11-24T09:23:31.000Z","size":722,"stargazers_count":17,"open_issues_count":4,"forks_count":6,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-11-27T21:51:51.631Z","etag":null,"topics":["arbitrary-precision","floating-point","gmp","gnu","integer","rational-numbers"],"latest_commit_sha":null,"homepage":null,"language":"D","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/nordlow.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2017-01-11T15:43:02.000Z","updated_at":"2025-11-14T05:19:33.000Z","dependencies_parsed_at":"2024-02-26T09:31:06.586Z","dependency_job_id":"aaca34dd-86c2-4eba-9c88-5bb93d0973dc","html_url":"https://github.com/nordlow/gmp-d","commit_stats":null,"previous_names":[],"tags_count":39,"template":false,"template_full_name":null,"purl":"pkg:github/nordlow/gmp-d","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nordlow%2Fgmp-d","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nordlow%2Fgmp-d/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nordlow%2Fgmp-d/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nordlow%2Fgmp-d/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nordlow","download_url":"https://codeload.github.com/nordlow/gmp-d/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nordlow%2Fgmp-d/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28756442,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-25T16:32:25.380Z","status":"ssl_error","status_checked_at":"2026-01-25T16:32:09.189Z","response_time":113,"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":["arbitrary-precision","floating-point","gmp","gnu","integer","rational-numbers"],"created_at":"2026-01-25T18:37:40.652Z","updated_at":"2026-01-25T18:37:40.723Z","avatar_url":"https://github.com/nordlow.png","language":"D","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gmp-d\n\nD-language high-level wrapper for [GNU MP (GMP) library](https://gmplib.org/)\nthat aims to be [mostly\ncompatible](https://github.com/nordlow/gmp-d/blob/master/src/gmp/z.d#L2030) with\n`std.bigint.BigInt` and `@safe pure nothrow @nogc` except when converting to\n`string`.\n\n## Basics\n\n- Integers (GMP's `mpz_t`) are wrapped in `gmp.z.MpZ`\n- Rationals (GMP's `mpq_t`) are wrapped in `gmp.q.MpQ`\n\nalong with most of their common operations implemented either as member\nfunctions, free functions or both.\n\n## Sample Usage\n\n### MpZ\n\n```D\nimport gmp.z;\n\n@safe pure nothrow @nogc:\n\nunittest {\n\talias Z = MpZ;\n\tassert(Z.mersennePrime(15) == 2^^15 - 1);\n\tconst a = 42.Z;\n\tconst b = a.dup; // explicit copying required\n}\n```\n\n### MpQ\n\n```D\nimport gmp.q;\n\n@safe pure nothrow @nogc:\n\nunittest {\n\talias Q = MpQ;\n\n\tQ x = Q(-4, 6);\n\n\tassert(x.numerator == -4);\n\tassert(x.denominator == 6);\n\n\tx.canonicalize();\n\n\tassert(x.numerator == -2);\n\tassert(x.denominator == 3);\n\n\tassert(inverse(x) == Q(-3, 2));\n\n\tassert(Q(1, 2) + Q(1, 3) == Q(5, 6));\n}\n```\n\n## Value passing\n\n### Value semantics with explicit copying and move\n\nFor `MpZ`, copy construction is disabled by default to prevent inadvertent\ncopying. Instead use `f(move(z))` or `f(z.move)` (from `std.algorithm.mutation`)\nto pass by move or `f(z.dup)` to pass by explicit copy (via `MpZ`'s member\nfunction `.dup`).\n\n### Value semantics with copy-on-write a la Phobos’ `std.bigint.BigInt`\n\nUse `Z` (`CopyableMpZ`), for a drop-in-replacement for Phobos’\n`std.bigint.BigInt`. For reference see\nhttps://dlang.org/phobos/std_bigint.html#.BigInt.\n\n## Mappings to GNU MP C library\n\nImplementation is optimized through\n\n- mapping of GMP's C macros into D inline functions that operate directly on the\n  internal C-representations `__mpz_struct` and `__mpq_struct`,\n\n- passing of `MpZ`-typed parameters as `auto ref const` in combination with\n  conditional compilation for r-value `MpZ` passed parameters via\n  `__traits(isRef)`. This enables clever reuse of `mpz_t` instances when passed\n  to `__gmpz`-functions. For instance, `x + 42.Z` can be lowered to\n\n```D\n__gmpz_add(rhs._ptr, this._ptr, rhs._ptr);\nreturn move(rhs);\n```\n\nin\n\n```D\nopBinary!\"+\"()(auto ref const MpZ rhs)\n```\n\n## Compilation Performance\n\nCompilation is fast; DMD compiles `gmp-d` in about 0.1 seconds on a modern\nmachine.\n\n## Run-time Performance\n\nWrapper is as light-weight as possible; Some D-functions directly access the\ninternal C-datastructure exposed by the structs and macros in the C-headers of\nGNU GMP.\n\n## Limitations\n\nNote that D's `__traits(isRef)` currently cannot be used to distinguish l-value\nfrom r-value passing of `this`. This severly limits the possibilities of using\nC++-style [expression\ntemplates](https://en.wikipedia.org/wiki/Expression_templates) to realize lazy\nevaluation in operator overloading. If this limitation were to be fixed\n(probably via some introspection mechanism other than the trait `isRef` or\nnon-`struct`-member operator overloading), this library could implement lowering\nof expressions such\n\n```D\nZ result = base^^exp % modulo\n```\n\nto the builtin\n\n```D\n__gmpz_powm(result._ptr, base._ptr, expr._ptr, modulo._ptr)\n```\n\nSee the unittests for `MpzAddExpr`, `MpzMulExpr`, etc for details on how this\ncurrently can be implemented and verified (in `ccc`-version) with free\nfunctions such `add` and `sub`.\n\n## Future\n\nThere are more `mpz_t`- and `mpq_t`-functions that should be wrapped but these are good start.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnordlow%2Fgmp-d","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnordlow%2Fgmp-d","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnordlow%2Fgmp-d/lists"}