June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -0,0 +1,87 @@
import system'math.
import extensions.
struct Quaternion :: BaseValue
{
real rprop A :: a.
real rprop B :: b.
real rprop C :: c.
real rprop D :: d.
constructor new(object a, object b, object c, object d)
<= new(a real, b real, c real, d real).
constructor new(real a, real b, real c, real d)
[
@a := a.
@b := b.
@c := c.
@d := d.
]
stacksafe explicit(Real r)
[
a := r.
b := 0.0r.
c := 0.0r.
d := 0.0r.
]
real Norm = (a*a + b*b + c*c + d*d) sqrt.
type<Quaternion> negative = Quaternion new(a negative,b negative,c negative,d negative).
type<Quaternion> Conjugate = Quaternion new(a,b negative,c negative,d negative).
type<Quaternion> add(Quaternion q)
= Quaternion new(a + q A, b + q B, c + q C, d + q D).
type<Quaternion> multiply(Quaternion q)
= Quaternion new(
a * q A - b * q B - c * q C - d * q D,
a * q B + b * q A + c * q D - d * q C,
a * q C - b * q D + c * q A + d * q B,
a * q D + b * q C - c * q B + d * q A).
type<Quaternion> add(real r)
<= add(Quaternion new(r,0,0,0)).
type<Quaternion> multiply(real r)
<= multiply(Quaternion new(r,0,0,0)).
bool equal(Quaternion q)
= (a == q A) && (b == q B) && (c == q C) && (d == q D).
literal
= String writeFormatted("Q({0}, {1}, {2}, {3})",a,b,c,d).
}
program =
[
var q := Quaternion new(1,2,3,4).
var q1 := Quaternion new(2,3,4,5).
var q2 := Quaternion new(3,4,5,6).
real r := 7.
console printLine("q = ", q).
console printLine("q1 = ", q1).
console printLine("q2 = ", q2).
console printLine("r = ", r).
console printLine("q.Norm() = ", q Norm).
console printLine("q1.Norm() = ", q1 Norm).
console printLine("q2.Norm() = ", q2 Norm).
console printLine("-q = ", q negative).
console printLine("q.Conjugate() = ", q Conjugate).
console printLine("q + r = ", q + r).
console printLine("q1 + q2 = ", q1 + q2).
console printLine("q2 + q1 = ", q2 + q1).
console printLine("q * r = ", q * r).
console printLine("q1 * q2 = ", q1 * q2).
console printLine("q2 * q1 = ", q2 * q1).
console printLineFormatted("q1*q2 {0} q2*q1", ((q1 * q2) == (q2 * q1)) iif("==","!=")).
].