gpt4 book ai didi

vector - 如何在 Ada 中添加向量

转载 作者:行者123 更新时间:2023-12-05 08:49:30 26 4
gpt4 key购买 nike

我有一个表示坐标的形式为 (x,y,x) 的向量。我希望能够执行类似 (x,y,z) + (x2,y2,z2) 的操作来生成一组新坐标。 Ada 说它不能对复合类型使用“+”,但我肯定有办法做到这一点?

最佳答案

如果你有

type Vector is record
X : Float;
Y : Float;
Z : Float;
end record;

你可以定义+

function "+" (L, R : Vector) return Vector is
(L.X + R.X, L.Y + R.Y, L.Z + R.Z);

在定义 - 时要小心,就像在整个过程中使用 - 一样!该错误非常难以发现。

关于vector - 如何在 Ada 中添加向量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63948479/

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