gpt4 book ai didi

fortran - 在内部类型上重载 Fortran 内部运算符?

转载 作者:行者123 更新时间:2023-12-05 01:52:02 25 4
gpt4 key购买 nike

代码

module pow_mod
implicit none
integer, parameter :: dp = kind(1.0d0)
interface operator(**)
module procedure mypow
end interface
contains
!
function mypow(x,y) result(x_to_y)
real(kind=dp), intent(in) :: x,y
real(kind=dp) :: x_to_y
x_to_y = exp(y*log(x))
end function mypow
end module pow_mod

gfortran 说

pow_fast.f90:5:25:

5 | module procedure mypow
| 1
Error: Operator interface at (1) conflicts with intrinsic interface

Intel Fortran 也有类似的说法。 Fortran 中是否可以在内部类型上重载内部运算符?

最佳答案

这样定义的操作是不允许的。来自 Fortran 2018 (15.4.3.4.2):

If the operator is an intrinsic-operator (R608), the number of dummy arguments shall be consistent with the intrinsic uses of that operator, and the types, kind type parameters, or ranks of the dummy arguments shall differ from those required for the intrinsic operation (10.1.5).

关于fortran - 在内部类型上重载 Fortran 内部运算符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71820344/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com