fortran - Fortran如何将实数转换为整数

标签 fortran fortran77

例如,

SUBROUTINE DoSomething (Z,L)                             
  IMPLICIT DOUBLE PRECISION (A-H,O-Z)                               

  D=Z*77.1234567D0                                           
  L=D                                                      

  RETURN                                                         
 END     

为了便于讨论,我们假设 D 等于 -1.5,在这种情况下 L 等于 -1 或 -2。 换句话说,是向上舍入还是向下舍入?

提前致谢。

最佳答案

使用内部函数 int 后,转换为整数类型进行赋值。效果定义为(F2008 13.7.81)

If A is of type real, there are two cases: if|A|<1, INT(A) has the value 0; if |A| ≥1, INT(A) is the integer whose magnitude is the largest integer that does not exceed the magnitude of A and whose sign is the same as the sign of A.

在这种情况下,L 将采用值 -1

关于fortran - Fortran如何将实数转换为整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45884588/

相关文章:

fortran - CHARACTER 声明及其 DATA 语句可以出现在 IMPLICIT 语句之前吗?

fortran - ISO_FORTRAN_ENV 或 -fdefault-real-8 将实数提升为 double

Fortran 数组和子程序(子数组)

debugging - Gfortran:将所有 block 视为 block

fortran - 如何让 FORTRAN 77 读取输入?

c - 链接 LAPACK/BLAS 库

linux - 无法在 Ubuntu 10.04、CUDA 5.0 上编译 MAGMA 1.3

为 ARM (Raspberry Pi) 交叉编译 R

random - 在 Fortran 77 中生成给定范围内的随机数

compilation - 子程序中未定义语句的Fortran问题