2

I'm working on some Fortran things, probably Fortran90 or Fortran95, and was wondering if GMP works with gfortran compiler. If so, how would one use the arbitrary precision arithmetic in gfortran? Also, does the Silverfrost Fortran compiler have an arbitrary arithmetic option? Does either gfortran or Silverfrost support something like Java's BigDecimal?

fishermanhat
  • 195
  • 1
  • 8
  • I don't know how recent a version of fortran needs to be, but yes you can use GMP. You need to manually translate the pieces of gmp.h that you care about (say at least the definition of `mpz_t` and the declarations of a few functions). `iso_c_binding`, `bind(C)` can help you find duplicates on this site (not specific to GMP). – Marc Glisse Nov 30 '19 at 21:04
  • @MarcGlisse, mpz_t is defined in terms of __mpz_struct, which uses `unsigned int` or `unsigned long`. ISO C binding does not include `unsigned` types. – evets Nov 30 '19 at 21:16
  • Asking for recommendation is typeically frowned on here. However, if you need arbitrary [precision entities look for David Baily's Fortran libraries on Netlib. – evets Nov 30 '19 at 21:17
  • @evets I think you can just use the signed types instead. The most important part is getting something the same size as __mpz_struct, but you won't ever look at the innards directly from fortran. – Marc Glisse Nov 30 '19 at 21:18
  • https://stackoverflow.com/q/38801846/1918193 – Marc Glisse Nov 30 '19 at 21:24
  • Usiing signed to describe the type is usually fine but one can always resort to opaque pointers. – Vladimir F Героям слава Nov 30 '19 at 22:55

0 Answers0