Vector products: Difference between revisions

Content deleted Content added
Peter (talk | contribs)
added Fantom example
Updated D code
Line 389:
=={{header|D}}==
<lang d>import std.stdio, std.conv, std.numeric;
 
immutable struct V3 {
union {
static immutable struct { double x, y, z; }
immutable double[3] v;
}
 
double dot(in V3 rhs) /*@safe*/ const pure nothrow {
return dotProduct(v, rhs.v);
}
 
V3 cross(in V3 rhs) @safe const pure nothrow {
return V3(y * rhs.z - z * rhs.y,
z * rhs.x - x * rhs.z,
x * rhs.y - y * rhs.x);
}
 
string toString() /*@safe*/ const { return text(v); }
}
 
double scalarTriple(in V3 a, in V3 b, in V3 c) pure nothrow {
/*@safe*/ pure nothrow {
return a.dot(b.cross(c));
}
 
V3 vectorTriple(in V3 a, in V3 b, in V3 c) @safe pure nothrow {
return a.cross(b.cross(c));
}
 
void main() {
immutable V3 a = {3, 4, 5},