gpt4 book ai didi

generics - Fortran 运算符

转载 作者:行者123 更新时间:2023-12-01 11:36:35 35 4
gpt4 key购买 nike

我正在使用 ^ 实现两个向量的叉积,但是我收到一个错误。不知道如何解决这个问题。

这是代码

Interface Operator (^)
Module Procedure vector_cross_product
End Interface Operator (^)

Contains

Function vector_cross_product (u, v) Result (w)

!!$ Input
Type (Vector), Intent(in) :: u, v

!!$ Output
Type (Vector) :: w

w% x = (u% y * v% z) - (u% z * v% y)
w% y = (u% z * v% x) - (u% x * v% z)
w% z = (u% x * v% y) - (u% y * v% x)

End Function vector_cross_product

这是我在使用 gfortran 时遇到的相应错误

Interface Operator (^)
1
Error: Syntax error in generic specification at (1)
lib/vectors.f:110.18:

Module Procedure vector_cross_product
1
Error: MODULE PROCEDURE at (1) must be in a generic module interface
lib/vectors.f:111.3:

End Interface Operator (^)
1
Error: Expecting END MODULE statement at (1)

最佳答案

我相信该标准排除了使用任意符号的可能性,例如 ^ , 在定义运算符时。在2008年的标准草案中我必须交出第7.1.6.1.4段的状态

A binary defined operation is an operation that has the form x1 defined-binary-op x2 or x1 intrinsic-operator x2 and that is defined by a function and a generic interface.

定义的二进制操作是停止之间的字母序列,例如 .cross..times. , 而内在运算符是语言标准中定义的运算符之一( +<* 等)。

由@francescalus 提出,我应该补充一点,序列不应超过 63 个字母,并且不应与任何内部运算符(例如 .eq)或逻辑文字(例如 .true.)相同

关于generics - Fortran 运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26493695/

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