{"id":23222705,"url":"https://github.com/pmunch/mapm-nim","last_synced_at":"2025-04-05T16:28:59.932Z","repository":{"id":192783369,"uuid":"687024829","full_name":"PMunch/mapm-nim","owner":"PMunch","description":"Matt's Arbitrary Precision Math library - Nim wrapper","archived":false,"fork":false,"pushed_at":"2024-07-30T07:05:28.000Z","size":140,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-11T13:24:58.671Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Nim","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/PMunch.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":"2023-09-04T12:48:30.000Z","updated_at":"2024-09-12T13:20:54.000Z","dependencies_parsed_at":null,"dependency_job_id":"2af2141b-c668-4510-ad75-d135de91610a","html_url":"https://github.com/PMunch/mapm-nim","commit_stats":null,"previous_names":["pmunch/mapm-nim"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PMunch%2Fmapm-nim","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PMunch%2Fmapm-nim/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PMunch%2Fmapm-nim/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PMunch%2Fmapm-nim/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PMunch","download_url":"https://codeload.github.com/PMunch/mapm-nim/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247364740,"owners_count":20927188,"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":[],"created_at":"2024-12-18T23:14:04.828Z","updated_at":"2025-04-05T16:28:59.909Z","avatar_url":"https://github.com/PMunch.png","language":"Nim","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Matt's Arbitrary Precision Math library\n\nThis is a wrapper for MAPM, an older but quite complete arbitrary math\nlibrary. The wrapper is made to be as close to the Nim maths module as\npossible so that it can function as a drop-in replacement when you realise\nthat you need better precision. The low-level wrapper is done through Futhark\nand both the `libmapm.a` and completed wrapper exists in this repo. If you\nwant or need to rebuild `libmapm.a` you can run the Nimble task `buildMapm`.\nIf you want Futhark to rebuild the wrapper you can compile with\n`-d:useFuthark` or `-d:useFutharkForMapm`.\n\nExample:\n\n```nim\nimport mapm\n\nvar x = initMapm(10) # Init a MAPM number from an existing int, float, or string\necho x / 6.4e+2'm # Or use the 'm literal specifier\n```\nPlease note that MAPM accumulates precision when multiplying numbers, so\nrounding to your required precision should be done from time to time to avoid\nthis. MAPM also handles errors by writing to stderr and return 0 in most\ncases. This wrapper could've wrapped the underlying functions in input checks\nand turned these into exceptions, but I opted not to do this for performance\nreasons.\n\nThe underlying C functions all take a MAPM number to store the result in.\nThis is wrapped to put the result in a freshly initialized number for each\noperation. This is likely to give a performance penalty over using the\nlibrary with the clever re-use of the result. If you want to squeeze the\nhighest amount of performance out of this library you should use the\nlow-level wrapper.\n\nThe rest of this documentation is more or less copied straight from the MAPM\nREADME.\n\n## MAPM library numerical limitations\n\nA general floating point number is of the form:\n\n```\nSn.nnnnnnnnE+yyyy        ex: -4.318384739357974916E+6215\nSn.nnnnnnnnE-yyyy        ex: +8.208237913789131096523645193E-12873\n```\n\n`S` is the sign, + or -.\n\nIn MAPM, a number (n.nnnn...) may contain up to ( INT_MAX - 1 ) digits.\n\nFor example, an MAPM number with a 16 bit integer may contain 2^15 or 32,767\ndigits. An MAPM number with a 32 bit integer may contain 2^31 or\n2,147,483,647 digits. All MAPM numbers are stored in RAM, there is no \"data\non disk\" option. So to represent the maximum number of digits on a 32 bit\nCPU will require greater than 2 Gig of RAM.\n\nIf you have a CPU with 64 bit ints, then the limitation is 2^63 or\n9,223,372,036,854,775,807. It should be a very long time before computers\nhave this much RAM in them.\n\nFor the exponent (yyyy), the limitations are also INT_MAX and INT_MIN.\n\nFor a 16 bit CPU, the largest number you can represent is approx\n0.9999999....E+32767.    (H)\n\nFor a 16 bit CPU, the smallest number you can represent (other than 0)\nis approx 0.1E-32767.   (L)\n\nFor a 32 bit CPU, the largest number you can represent is approx\n0.9999999....E+2147483647.   (H)\n\nFor a 32 bit CPU, the smallest number you can represent (other than 0)\nis approx 0.1E-2147483647.  (L)\n\nThe limitations for negative numbers are the same as positive numbers.\n\n```\n                            Real Number Axis\n\n     +------------------------+    ---    +--------------------------+\n     |                        |     |     |                          |\n    -H                       -L    0.0   +L                         +H\n```\n\nMAPM can represent real numbers from -H to -L, 0.0, +L to +H.\n\nThe number of significant digits is typically only limited by available RAM.\n\nIn MAPM, numerical overflows and underflows are not handled very well\n(actually not at all). There really isn't a clean and portable way to\ndetect integer overflow and underflow. Per K\u0026R C, the result of integer\noverflow/underflow is implementation dependent. In assembly language, when\nyou add two numbers, you have access to a \"carry flag\" to see if an overflow\noccurred. C has no analogous operator to a carry flag.\n\nIt is up to the user to decide if the results are valid for a given\noperation. In a 32 bit environment, the limit is so large that this is likely\nnot an issue for most typical applications. However, it doesn't take much to\noverflow a 16 bit int so care should taken in a 16 bit environment.\n\nThe reaction to an integer overflow/underflow is unknown at run-time:\n\n- Adding 2 large positive numbers may silently roll over to a negative\n  number.\n- In some embedded applications an integer overflow/underflow triggers a\n  hardware exception.\n\n## Thread safety\nNote that the default MAPM library is *NOT* thread safe. MAPM internal data\nstructures could get corrupted if multiple MAPM functions are active at the\nsame time. The user should guarantee that only one thread is performing MAPM\nfunctions. This can usually be achieved by a call to the operating system to\nobtain a 'semaphore', 'mutex',  or 'critical code section' so the operating\nsystem will guarantee that only one MAPM thread will be active at a time.\n\nThis file is automatically generated from the documentation found in\nsrc/mapm.nim. Use `nim doc src/mapm.nim` to get the full documentation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpmunch%2Fmapm-nim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpmunch%2Fmapm-nim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpmunch%2Fmapm-nim/lists"}