Skip to content

Element.div is wasting floating point precision on trivectors with length 1 #3

Description

@kungfooman

There is this "trick" to solve linear equations in all kinds of GA books:

GAmphetamine(3, () => {
  // --- Vektor Definitionen (Spalten) ---
  const v0 = 2*1e1 + 5*1e2 + 3*1e3;
  const v1 = 3*1e1 + 1*1e2 + 2*1e3;
  const v2 = 4*1e1 + 6*1e2 + 1*1e3;
  const target = 32*1e1 + 47*1e2 + 18*1e3;
  // --- Nenner-Volumen berechnen ---
  const vol = v0 ^ v1 ^ v2;
  console.log("Volumen: ", vol);
  // --- Lösungen berechnen (Zähler / Nenner) ---
  // Variable 0
  const num0 = target ^ v1 ^ v2;
  const ans0 = num0 / vol;
  console.log("num0: ", num0);
  console.log("135/45", 135/45); // 3
  console.log("Ergebnis Variable 0: ", ans0); // 3.000000072643161
  // Variable 1
  const num1 = v0 ^ target ^ v2;
  const ans1 = num1 / vol;
  console.log("Ergebnis Variable 1: ", ans1);
  // Variable 2
  const num2 = v0 ^ v1 ^ target;
  const ans2 = num2 / vol;
  console.log("Ergebnis Variable 2: ", ans2);
});

Result:

Ergebnis Variable 0:  3.000000072643161
Ergebnis Variable 1:  2.000000048428774
Ergebnis Variable 2:  5.000000121071935

Instead of calculating 3 it's calculating 3.000000072643161 because it goes through the entire inverse. But it's both just two trivectors with one number component anyway:

Image

We should be able to just check if both element have length 1 and do "normal" division?

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions