Vector3 normalization leaves weird values

Hi, i’m working on a school project and i’m having a problem with Vector3.normalized.

I have these 3 vectors.

Vector3 e = new Vector3(10, 0, 0);
        Vector3 v = new Vector3(-1, 0, 0);
        Vector3 u = new Vector3(
                    (Mathf.Cos(Mathf.PI) * Mathf.Cos(0 + Mathf.PI / 2)),
                    (Mathf.Sin(Mathf.PI) * Mathf.Cos(0 + Mathf.PI / 2)),
                    Mathf.Sin(0 + Mathf.PI / 2));

And then this operation

Vector3 res1 = (v * -1.0f).normalized;
        Vector3 res2 = Vector3.Cross(u, res1).normalized;
        Vector3 res3 = Vector3.Cross(res1, res2);

But res2 and res3 contains some weird values, you can see it on image below
59561-unity.png
As you can see the problem is the z coordinate, i need that vector to contain only 1 or 0 as the string normalized version shows.

Any tips why these values are still in that vector after normalized?
Thanks for any help.

This is the nature of floating point values. The value displayed is in scientific notation. The E-15 basically means take the number displayed (3.821371) and move the decimal point 15 places to the left. What you end up with is effectively 0, but due to floating point rounding and precision and such during the calculations you end up with a slightly non-zero value. When display vectors, Unity rounds them to 10ths.

If you really want them to be zero you can examine the x,y,z values and set them to zero if they are Mathf.Approximately(0). Unless it’s something specific to your assignment this is something you don’t need to worry about. The normalization math is correct, the length of the vector is 1 or close enough to 1 as to make no material difference.

If you want to learn the why’s about floating point you should read the article What Every Computer Scientist Should Know about Floating Point.