5

For a language designed for scientific computing---even 50ish years ago, I am surprised to find that Fortran 2018 didn't have a native type for bignum or bigInt types for arbitrary precision, and suspect I am doing something wrong. What is the standard process for this?

I'm thinking:

program toosmall
  ! compile with:
  ! gfortran -fno-range-check -o toosmall toosmall.f90 

  implicit none

  integer :: base, pow, res

  base = 1000
  pow  = 100000

  res= base**pow

  print *,res

end program toosmall

And this produces

$ ./toosmall 
           0
Mittenchops
  • 18,633
  • 33
  • 128
  • 246
  • 5
    Sadly, your expectations of Fortran are unrealistic. There are, I believe, other programming languages which implement big-integer arithmetic straight out of the box. Fortran provides all the bits and pieces you need to write your own big-integer implementation and there are plenty of libraries for big-integers to which you might integrate. – High Performance Mark Oct 08 '19 at 06:51
  • 4
    Fortran is a general purpose programming language with numerical types similar to those of C and C++. Those numeric types are fixed-storage-size. In all these languages one uses additional libraries to enable the large integer arithmetic, like https://gmplib.org/ and other ones. C libraries can be interfaced from Fortran and you may even find Fortran libraries or interfaces ready to use. It will never be as simple as writing `pow = 100000000000000000000000` though. Python (where such support exists) is not really a direct competitor to Fortran. C++ is. – Vladimir F Героям слава Oct 08 '19 at 08:45
  • 1
    Thank you, @kvantour. I'm aware of how big the universe is, but this computation is not unrealistic if your problem demands it. Also, python can do this trivially: ```x = 10**200; '1.00E+200'``` – Mittenchops Oct 08 '19 at 12:57
  • I can improve the question by making this a smaller big integer that still throws the error though, in the spirit of minimal reproducible examples. One sec. – Mittenchops Oct 08 '19 at 12:59
  • Thanks @VladimirF. What /is/ a good minimum that still shows this off? Back to the original or something in between? – Mittenchops Oct 08 '19 at 13:20
  • 2
    Actually, even the small example was fine and for exponentiation more than enough, I did not realize the `pow` is the larger one. Sorry. Still even better is to have a general number instead of just zeros, but that is cosmetic. – Vladimir F Героям слава Oct 08 '19 at 13:29
  • 1
    It's difficult to understand what kind of answer you would like in return for the munificent bounty you offer. The answer to the question you ask is *there is no standard Fortran approach to bignum arithmetic*, as has already been explained in comments. – High Performance Mark Oct 10 '19 at 21:55
  • See Richard Brent's [MP](https://maths-people.anu.edu.au/~brent/pub/pub043.html), David Smith's [FM](https://dmsmith.lmu.build/) or David Bailey's [MPFUN](https://www.davidhbailey.com/dhbsoftware/). These are pure Fortran libraries. These is also a [Fortran binding](https://sourceforge.net/projects/gmp-fortran-library/files/) do GMP. –  Sep 03 '20 at 13:59

0 Answers0