对于一种专为科学计算而设计的语言-甚至是50年前,我惊讶地发现Fortran 2018没有针对bignum或bigInt类型的本机类型以实现任意精度,并且怀疑我做错了什么。这是什么标准流程?
我在想:
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
Run Code Online (Sandbox Code Playgroud)
这产生了
$ ./toosmall
0
Run Code Online (Sandbox Code Playgroud) 如何在 Fortran 中进行任意精度算术?
我需要两件事。我想处理非常大的整数和实数,并处理任意精确的实数。
我正在尝试使用大数(~10 ^ 14),我需要能够存储它们并迭代那个长度的循环,即
n=SOME_BIG_NUMBER
do i=n,1,-1
Run Code Online (Sandbox Code Playgroud)
我尝试了通常的星形符号kind=8等,但似乎没有任何效果.然后我检查了huge内在函数和代码:
program inttest
print *,huge(1)
print *,huge(2)
print *,huge(4)
print *,huge(8)
print *,huge(16)
print *,huge(32)
end program inttest
Run Code Online (Sandbox Code Playgroud)
在所有情况下产生数字2147483647.为什么是这样?我在64位机器上使用gfortran(f95).
如果我需要一个bignum图书馆,人们会建议哪一个?