[No translation] A math library I wanted to share

Headers, Bindings, Libraries for use with FreeBASIC, Please include example of use to help ensure they are tested and usable.
Post Reply
j8w344c6
Posts: 184
Joined: Oct 25, 2021 10:18

[No translation] A math library I wanted to share

Post by j8w344c6 »

It's here: https://github.com/creachadair/imath

There is no translation included because... I just can't believe it. You just run fbfrog on the .h and it generated the corresponding .bi without any TODOs. It's too easy so I'm really not sure if the translated headers really correct or not.

There is an example here I took from their github page above. If you could translate it to FreeBASIC then please check if the headers translated by fbfrog really work. I personally know nothing about this kind of arbitrary precision math library so I can't test it myself. I have no idea what the code is doing.

Code: Select all

#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;
}
miilvyxg
Posts: 193
Joined: Dec 07, 2021 6:51

Re: [No translation] A math library I wanted to share

Post by miilvyxg »

This library is about integer math only, not floating point math. Useless anyone. Don't even attempt to try. It's just wasting your time.
Post Reply