I have a vector of the form (x,y,x) representing coordinates. I want to be able to do something like (x,y,z) + (x2,y2,z2) to produce a new set of coordinates. Ada says it cant use '+' for composite types, but surely there is a way I can do this?
How to add vectors in Ada
365 views Asked by Ben At
2
There are 2 answers
0
On
If you define your vectors to contain elements of a floating point type you can use the generic package Ada.Numerics.Generic_Real_Arrays. This package is described in the Ada Language Reference Manual section G.3.1.
If you want to define your vectors to contain elements of a complex number type then you can use the generic package described in section G.3.2 Complex Vectors and Matrices
If you wish to use integer types as your vector components you can write the "+" function for your integer vector type.
If you have
you can define
+
asBe careful when you define
-
similarly to use-
throughout! that error is very hard to spot.