Calculate vector unit without square root
<p>I need to calculate the unit vector for arbitrary vectors. The clue is that I don't want to introduce floating point errors, so I can't afford to use the sqrt() function. In order to do arithmetic and don't introduce floating point errors, I use a Rational datatype.</p>

<pre><code>public class Vector3
{
    public Rational X { get; set; }
    public Rational Y { get; set; }
    public Rational Z { get; set; }

    public Vector3(Rational x, Rational y, Rational z)
    {
        X = x;
        Y = y;
        Z = z;
    }
    .....
</code></pre>

<p>and my vector unit calculation looks like this:</p>

<pre><code>    public Vector3 Unit()
    {
        if (this.Length() == 0)
            return new Vector3(0, 0, 0);
        return this.DividedBy(this.Length());
    }

    public Rational Length()
    {
        return Sqrt(Dot(this).ToDouble());
    }

    public Rational Dot(Vector3 a)
    {
        return this.X * a.X + this.Y * a.Y + this.Z * a.Z;
    }
</code></pre>

<p>The problem is the Sqrt() method because I have to convert my Rational to a double. Moreover, the Sqrt() produces an irrational number. So I have a possible roundoff error in the input and in the ouput of the sqrt function.</p>

<p>So I need to calculate the length of the vector without a square root. Is that possible?</p>