All Projects → creachadair → imath

creachadair / imath

Licence: other
Arbitrary precision integer and rational arithmetic library

Programming Languages

c
50402 projects - #5 most used programming language
python
139335 projects - #7 most used programming language
scheme
763 projects
Makefile
30231 projects

Projects that are alternatives of or similar to imath

cldr-engine
Internationalization and localization in Typescript with Unicode CLDR, batteries included
Stars: ✭ 34 (-63.04%)
Mutual labels:  math, arbitrary-precision
Surge
A Swift library that uses the Accelerate framework to provide high-performance functions for matrix math, digital signal processing, and image manipulation.
Stars: ✭ 4,945 (+5275%)
Mutual labels:  math, arithmetic
Angourimath
Open-source symbolic algebra library for C# and F#. One of the most powerful in .NET
Stars: ✭ 266 (+189.13%)
Mutual labels:  math, arbitrary-precision
Calc
C-style arbitrary precision calculator
Stars: ✭ 127 (+38.04%)
Mutual labels:  math, arbitrary-precision
30secondchallenge
Inspired by the newspaper puzzle my wife's grandma tests me with each time I visit.
Stars: ✭ 19 (-79.35%)
Mutual labels:  math, arithmetic
Javascript Biginteger
A big integer library for JavaScript
Stars: ✭ 181 (+96.74%)
Mutual labels:  math, arbitrary-precision
Rpn
Math functional language, inspired by Hewlett-Packard Reverse Polish Notation (RPL) language
Stars: ✭ 17 (-81.52%)
Mutual labels:  math, arbitrary-precision
Tensor
A library and extension that provides objects for scientific computing in PHP.
Stars: ✭ 146 (+58.7%)
Mutual labels:  math, arithmetic
bcmath-extended
Extends php BCMath lib for missing functions like floor, ceil, round, abs, min, max, rand for big numbers. Also wraps existing BCMath functions.
Stars: ✭ 59 (-35.87%)
Mutual labels:  math, arbitrary-precision
keisan
A Ruby-based expression parser, evaluator, and programming language
Stars: ✭ 48 (-47.83%)
Mutual labels:  math
SharpMath2
2D math / geometry collision library for C#, compatable with monogame.
Stars: ✭ 36 (-60.87%)
Mutual labels:  math
Euler
The open-source computational framework for the Swift language
Stars: ✭ 37 (-59.78%)
Mutual labels:  math
Online-Tools
Webpage offering a wide range of online tools
Stars: ✭ 38 (-58.7%)
Mutual labels:  math
IwEngine
This is an engine that I initially started building after taking a game coding class in high school. I didn't like Unity so tried to make something more code focused that was personally easier to use.
Stars: ✭ 97 (+5.43%)
Mutual labels:  math
combi
Pythonic package for combinatorics
Stars: ✭ 51 (-44.57%)
Mutual labels:  math
StuyLib
Award-Winning FRC Library by StuyPulse Team 694
Stars: ✭ 17 (-81.52%)
Mutual labels:  math
ChangePrecision.jl
macro to change the default floating-point precision in Julia code
Stars: ✭ 28 (-69.57%)
Mutual labels:  math
vecti
A tiny TypeScript library for 2D vector math.
Stars: ✭ 14 (-84.78%)
Mutual labels:  math
algorithm
📌 Notes and Codes for studying data structures and algorithm
Stars: ✭ 72 (-21.74%)
Mutual labels:  math
exponential-moving-average
Calculate an exponential moving average from an array of numbers.
Stars: ✭ 41 (-55.43%)
Mutual labels:  math

IMath

Arbitrary precision integer and rational arithmetic library.

Unit tests

IMath is an open-source ISO C arbitrary precision integer and rational arithmetic library.

IMath is copyright © 2002-2009 Michael J. Fromberger.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About IMath

IMath is a library written in portable ISO C that allows you to perform arithmetic on integers and rational numbers of arbitrary precision. While many programming languages, including Java, Perl, and Python provide arbitrary precision numbers as a standard library or language feature, C does not.

IMath was designed to be small, self-contained, easy to understand and use, and as portable as possible across various platforms. The API is simple, and the code should be comparatively easy to modify or extend. Simplicity and portability are useful goals for some applications—however, IMath does not attempt to break performance records. If you need the fastest possible implementation, you might consider some other libraries, such as GNU MP (GMP), MIRACL, or the bignum library from OpenSSL.

Programming with IMath

Detailed descriptions of the IMath API can be found in doc.md. However, the following is a brief synopsis of how to get started with some simple tasks.

To do basic integer arithmetic, you must declare variables of type mpz_t in your program, and call the functions defined in imath.h to operate on them. Here is a simple example that reads one base-10 integer from the command line, multiplies it by another (fixed) value, and prints the result to the standard output in base-10 notation:

#include <stdio.h>
#include <stdlib.h>
#include "imath.h"

int main(int argc, char *argv[])
{
  mpz_t  a, b;
  char  *buf;
  int    len;

  if(argc < 2) {
    fprintf(stderr, "Usage: testprogram <integer>\n");
    return 1;
  }

  /* Initialize a new zero-valued mpz_t structure */
  mp_int_init(&a);

  /* Initialize a new mpz_t with a small integer value */
  mp_int_init_value(&b, 25101);

  /* Read a string value in the specified radix */
  mp_int_read_string(&a, 10, argv[1]);

  /* Multiply the two together... */
  mp_int_mul(&a, &b, &a);

  /* Print out the result */
  len = mp_int_string_len(&a, 10);
  buf = calloc(len, sizeof(*buf));
  mp_int_to_string(&a, 10, buf, len);
  printf("result = %s\n", buf);
  free(buf);

  /* Release memory occupied by mpz_t structures when finished */
  mp_int_clear(&b);
  mp_int_clear(&a);

  return 0;
}

This simple example program does not do any error checking, but all the IMath API functions return an mp_result value which can be used to detect various problems like range errors, running out of memory, and undefined results.

The IMath API also supports operations on arbitrary precision rational numbers. The functions for creating and manipulating rational values (type mpq_t) are defined in imrat.h, so that you need only include them in your project if you wish to.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].