Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Fortran 如何将一个大值赋给一个8字节的整数变量并打印该值?_Fortran - Fatal编程技术网

Fortran 如何将一个大值赋给一个8字节的整数变量并打印该值?

Fortran 如何将一个大值赋给一个8字节的整数变量并打印该值?,fortran,Fortran,我尝试用Fortran对8字节整数执行以下简单赋值: integer(kind=8) :: a a = 30 * 1000000000 print *,a 但是,当我打印值时,我会得到以下输出: -64771072 这看起来像是用4个字节完成了打印或30*100000000计算 问题是在变量赋值中,还是在打印或其他地方 我怎样才能修好它 它是否依赖于特定的Fortran标准 我在64位FreeBSD系统中使用flang,以防相关 编辑: 根据评论建议,我已下载并执行了kindfin

我尝试用Fortran对8字节整数执行以下简单赋值:

integer(kind=8)    :: a
a = 30 * 1000000000
print *,a
但是,当我打印值时,我会得到以下输出:

-64771072
这看起来像是用4个字节完成了
打印
30*100000000
计算

  • 问题是在变量赋值中,还是在打印或其他地方
  • 我怎样才能修好它
  • 它是否依赖于特定的Fortran标准
我在64位FreeBSD系统中使用
flang
,以防相关

编辑

根据评论建议,我已下载并执行了
kindfind.f90
。这是输出。我的理解是,在我的编译器中,kind=8将按照程序描述()提供8字节


刚刚上床睡觉,但kind=8不能保证是8字节整数,也不能保证编译器支持它。使用选定的\u int\u kind或iso\u fortran\u env可移植地获取合适的种类。有关reals的工作原理,请参见。整数的工作原理类似。然后,要得到一个包含适当范围的整数的表达式,只需使用适当的种类,包括常数。我将把
kindfind.f90
的输出添加到原始问题中。@M.E.是的,我们知道是这样的,否则编译器会提前拒绝该程序。但关键是,您不应该直接使用这些值,如4或8。下一个使用您的代码的人可能会使用不同的编译器。即使是还不存在的编译器。重复问题中提供的答案有助于理解如何处理此问题。
$ ./a.out 



 !---------------------------------------------------------!
 !                                                         !
 !                    KINDFINDER                           !
 !                                                         !
 !            KIND Search & Evaluation for                 !
 !          FloatingPoint and Integer Types                !
 !           of the local Fortran Compiler                 !
 !                                                         !
 ! Author: Werner W Schulz (C) 1998                        !
 ! (email: wws20@cam.ac.uk)                                !
 !                                                         !
 !                                                         !
 ! FloatingPoint Model Parameters:                         !
 ! Kind   Precision       Range          Name              !
 !    4           6          37          Single            !
 !    8          15         307          Double            !
 !                                                         !
 !                                                         !
 ! Integer Model Parameters:                               !
 ! Kind   Range                          Name              !
 !    1       2                          Int_01            !
 !    2       4                          Int_02            !
 !    4       9                         Int_Def            !
 !    8      18                          Int_08            !
 !                                                         !
 !                                                         !
 !                                                         !
 ! NOTE:                                                   !
 ! KindFinder has generated a Programme and a Module in    !
 !                                                         !
 !     NumericModel.f90                                    !
 !     Fortran_Kind_Module.f90                             !
 !                                                         !
 ! that will compute and display the Numerical Parameters  !
 ! of the various INTEGER & FLOATING POINT Types           !
 ! as specified by Fortran and the local Compiler.         !
 ! The ModuleFile is can be used elsewhere.                !
 !                                                         !
 ! All Code is compatible with the Fortran Subsets and     !
 ! should be able to run on any Fortran90-conforming       !
 ! Compiler including F and Elf90.                         !
 !                                                         !
 ! NOTE:                                                   !
 ! Possible KIND Values for LOGICAL or CHARACTER Types     !
 ! must be obtained in the local Fortran Reference Manual  !
 !                                                         !
 !---------------------------------------------------------!



Warning: ieee_inexact is signaling
FORTRAN STOP
$