{"id":18955757,"url":"https://github.com/creachadair/imath","last_synced_at":"2025-04-04T21:06:12.250Z","repository":{"id":4570363,"uuid":"5711810","full_name":"creachadair/imath","owner":"creachadair","description":"Arbitrary precision integer and rational arithmetic library","archived":false,"fork":false,"pushed_at":"2025-03-18T15:58:39.000Z","size":1302,"stargazers_count":140,"open_issues_count":6,"forks_count":21,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-03-28T20:11:12.463Z","etag":null,"topics":["arbitrary-precision","arithmetic","c","math"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/creachadair.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog","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":"2012-09-07T02:58:40.000Z","updated_at":"2025-03-22T22:49:34.000Z","dependencies_parsed_at":"2024-02-26T17:46:59.683Z","dependency_job_id":"69942724-3a2a-4d8e-b530-2b24f1bd9ce9","html_url":"https://github.com/creachadair/imath","commit_stats":{"total_commits":202,"total_committers":13,"mean_commits":"15.538461538461538","dds":0.1732673267326733,"last_synced_commit":"745fceb8827eb0ba9dc00db58e889a03dcaaf1bd"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creachadair%2Fimath","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creachadair%2Fimath/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creachadair%2Fimath/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creachadair%2Fimath/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/creachadair","download_url":"https://codeload.github.com/creachadair/imath/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247249524,"owners_count":20908212,"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":["arbitrary-precision","arithmetic","c","math"],"created_at":"2024-11-08T13:50:08.131Z","updated_at":"2025-04-04T21:06:12.227Z","avatar_url":"https://github.com/creachadair.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"IMath\n=====\n\nArbitrary precision integer and rational arithmetic library.\n\n[![Unit tests](https://github.com/creachadair/imath/workflows/Unit%20tests/badge.svg)](https://github.com/creachadair/imath/actions/workflows/unit-tests.yml)\n\nIMath is an open-source ISO C arbitrary precision integer and rational\narithmetic library.\n\nIMath is copyright \u0026copy; 2002-2009 Michael J. Fromberger.\n\n\u003e Permission is hereby granted, free of charge, to any person obtaining a copy\n\u003e of this software and associated documentation files (the \"Software\"), to deal\n\u003e in the Software without restriction, including without limitation the rights\n\u003e to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n\u003e copies of the Software, and to permit persons to whom the Software is\n\u003e furnished to do so, subject to the following conditions:\n\u003e\n\u003e The above copyright notice and this permission notice shall be included in\n\u003e all copies or substantial portions of the Software.\n\u003e\n\u003e THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n\u003e IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n\u003e FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\n\u003e AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n\u003e LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n\u003e OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n\u003e SOFTWARE.\n\n\nAbout IMath\n-----------\n\nIMath is a library written in portable ISO C that allows you to perform\narithmetic on integers and rational numbers of arbitrary precision.  While many\nprogramming languages, including Java, Perl, and Python provide arbitrary\nprecision numbers as a standard library or language feature, C does not.\n\nIMath was designed to be small, self-contained, easy to understand and use, and\nas portable as possible across various platforms.  The API is simple, and the\ncode should be comparatively easy to modify or extend.  Simplicity and\nportability are useful goals for some applications\u0026#8212;however, IMath does\nnot attempt to break performance records.  If you need the fastest possible\nimplementation, you might consider some other libraries, such as GNU MP (GMP),\nMIRACL, or the bignum library from OpenSSL.\n\nProgramming with IMath\n----------------------\n\nDetailed descriptions of the IMath API can be found in [doc.md](doc.md).\nHowever, the following is a brief synopsis of how to get started with some\nsimple tasks.\n\nTo do basic integer arithmetic, you must declare variables of type `mpz_t` in\nyour program, and call the functions defined in `imath.h` to operate on them.\nHere is a simple example that reads one base-10 integer from the command line,\nmultiplies it by another (fixed) value, and prints the result to the standard\noutput in base-10 notation:\n\n```c\n#include \u003cstdio.h\u003e\n#include \u003cstdlib.h\u003e\n#include \"imath.h\"\n\nint main(int argc, char *argv[])\n{\n  mpz_t  a, b;\n  char  *buf;\n  int    len;\n\n  if(argc \u003c 2) {\n    fprintf(stderr, \"Usage: testprogram \u003cinteger\u003e\\n\");\n    return 1;\n  }\n\n  /* Initialize a new zero-valued mpz_t structure */\n  mp_int_init(\u0026a);\n\n  /* Initialize a new mpz_t with a small integer value */\n  mp_int_init_value(\u0026b, 25101);\n\n  /* Read a string value in the specified radix */\n  mp_int_read_string(\u0026a, 10, argv[1]);\n\n  /* Multiply the two together... */\n  mp_int_mul(\u0026a, \u0026b, \u0026a);\n\n  /* Print out the result */\n  len = mp_int_string_len(\u0026a, 10);\n  buf = calloc(len, sizeof(*buf));\n  mp_int_to_string(\u0026a, 10, buf, len);\n  printf(\"result = %s\\n\", buf);\n  free(buf);\n\n  /* Release memory occupied by mpz_t structures when finished */\n  mp_int_clear(\u0026b);\n  mp_int_clear(\u0026a);\n\n  return 0;\n}\n```\n\nThis simple example program does not do any error checking, but all the IMath\nAPI functions return an `mp_result` value which can be used to detect various\nproblems like range errors, running out of memory, and undefined results.\n\nThe IMath API also supports operations on arbitrary precision rational numbers.\nThe functions for creating and manipulating rational values (type `mpq_t`) are\ndefined in `imrat.h`, so that you need only include them in your project if you\nwish to.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcreachadair%2Fimath","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcreachadair%2Fimath","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcreachadair%2Fimath/lists"}