Float percision: Yes I am asking this question agian because it doesn't make sense

So, yes I am asking the same question again, and I am sure others have asked this too. However, I disagree with the answers that I had recieved when I previously asked this before. I do not understand that this is one of programmers delimmas because it has to do with how your computer processes numbers. If that is the case then how is it that most Game Level Editors, never produce a expotent notation numbers in the vector coordinates of x, y, and z? This is so anoying, especially when you are trying to find the matrix rotation and multiply it by a vector to find the point direction, and the matrix has a bunch of exponent numbers instead of saying they are zero.

for example, look at this…

if variable mat => Matrix(((-1.0, 7.065134468575707e-06, 0.0), (-7.065134468575707e-06, -1.0, 0.0), (0.0, 0.0, 1.0)))
and you multiply this by Vector(-1, 0, 0) the result is Vector((1.0, -8.742277657347586e-08, 0.0)) which is absoluty 100% wrong becuase this means that the y axis is almost -1, but the correct answer show be Vector((1, 0, 0))

So what you are saying is that you don’t like the way that floating-points are displayed? Where are you seeing these exponents? Python console? Blender interface?

Blender Python says:

>>> Matrix(((-1.0, 7.065134468575707e-06, 0.0), (-7.065134468575707e-06, -1.0, 0.0), (0.0, 0.0, 1.0)))*Vector((-1,0,0))
Vector((1.0, 7.065134468575707e-06, 0.0))

This is the correct answer. It is also very close to Vector((1.0, 0.0, 0.0)). For that matter, -8.742277657347586e-08 (wherever it came from) is even closer to 0.0.

Best wishes,
Matthew

well if it is just a display problem, then I would not be so concerned. My concern is exponent values can eventually be multiplied by some number in which the answer can make a huge impact on which way a vector is pointing. For example Vector((1, 0.0001, 0)) is not the same as Vector((1, 0, 0)). You might think, well gee, 0.0001 does not sound so bad, but when you are modeling a city that is in meters units, and your character is 1.75 meters tall, it is possible the player will see that things are missed aligned. On the other hand, if it is suppose to be zero, then multipliying any number by zero is always zero, which IMHO, that is key!

BTW, the matrix given above was not correct. using this one…
Matrix(Vector((7.549790126404332e-08, -1.0, 0.0, 0.0)), Vector((1.0, 7.549790126404332e-08, 0.0, 0.0)), Vector((0.0, 0.0, 1.0, 0.0)), Vector((0.0, 0.0, 0.0, 1.0)))
… which is a Rotation Matrix that has been rotated 90 degrees in the ‘Z’ axis. This means that, using our right-handed rule a ‘-X’ axis direction is now pointing in the ‘-Y’ axis direction

Yes, I know, I worded myself wrong. I forgot to mention if I used the floor() function to get rid of the exponent value, floor(-8.742277657347586e-08) is equal to -1, which results in a wrong answer.

Other than that, I guess my real question in mind is… how do I make decimal exponent values be zero

0.87 / 100000000 isn’t 0.0001 it’s less than 0.0000001, which means your 1.75 metre tall character notice a change of less than 1 millimetre every 10 kilometres? Gee that doesn’t sound so bad.

BTW, the matrix given above was not correct. using this one…
Matrix(Vector((7.549790126404332e-08, -1.0, 0.0, 0.0)), Vector((1.0, 7.549790126404332e-08, 0.0, 0.0)), Vector((0.0, 0.0, 1.0, 0.0)), Vector((0.0, 0.0, 0.0, 1.0)))
… which is a Rotation Matrix that has been rotated 90 degrees in the ‘Z’ axis. This means that, using our right-handed rule a ‘-X’ axis direction is now pointing in the ‘-Y’ axis direction

Yes, I know, I worded myself wrong. I forgot to mention if I used the floor() function to get rid of the exponent value, floor(-8.742277657347586e-08) is equal to -1, which results in a wrong answer.

110% wrong. This could result in misalignment of 1 metre … every metre!

Other than that, I guess my real question in mind is… how do I make decimal exponent values be zero

For the zero case, you could ( I don’t recommend this) check the absolute value against some tolerance, and replace with 0 if under.


def zero_element_under_tol(m, tol=1e-6):
    indexes = [(i,j) for i, row in enumerate(m.row) 
           for j, v in enumerate(row) 
           if abs(v) < tol]
    for i, j in indexes:
        m[i][j] = 0




>>> m = Matrix.Rotation(radians(90), 3,  'Z')
>>> m
Matrix(((7.549790126404332e-08, -1.0, 0.0),
        (1.0, 7.549790126404332e-08, 0.0),
        (0.0, 0.0, 1.0)))


>>> zero_matrix_under_tol(m)
>>> m
Matrix(((0.0, -1.0, 0.0),
        (1.0, 0.0, 0.0),
        (0.0, 0.0, 1.0)))


>>> 

The above will result in some rounding. The more you round the less precision you have in your final results. I have a feeling your issue here is with the string representation of a Matrix or Vector when you print it. If this is the case, set up a little method like above that prints your Matrix Vector with formatting.


print("%0.2f" % 0.45454542453345e-8)

will output 0.00

, rather than replacing small elements with zero.