Vector().normalized() doesn't seem to work as expected

I’m noticing some inconsistent behavior when using the normalized() method on a vector object. When printing the values of the vector using print(), it displays the expected values, but when I access the x, y, and z values directly it returns the un-normalized values. Here’s an example (I’m currently testing on 2.93.2):

# This is using a sun lamp in the scene as the active object
rot = C.object.rotation_euler.copy()

print(rot) # returns "Euler((0.0, 0.0, 0.0), 'XYZ')"

rot.x += math.radians(90)

print(rot) # returns "Euler((1.5707963705062866, 0.0, 0.0), 'XYZ')"

# Get the right, up, and back vectors
right, up, back = rot.to_matrix().transposed()

print(back) # returns "Vector((0.0, -1.0, -4.371138828673793e-08))"

norm = back.normalized()

print(norm) # returns "<Vector (0.0000, -1.0000, -0.0000)>"
print(norm.x) # returns 0.0
print(norm.y) # returns -1.0

# THIS IS THE ISSUE
print(norm.z) # returns -4.371138828673793e-08, not 0.0 as expected

Am I missing something fundamental about how the normalized() function works or is this a bug?

that is pretty damn close to zero, how accurate do you need it to be? :grinning_face_with_smiling_eyes:

in all seriousness, that’s scientific notation

Most calculators and many computer programs present very large and very small results in scientific notation, typically invoked by a key labelled EXP (for exponent ), EEX (for enter exponent ), EE, EX, E, or ×10x depending on vendor and model. Because superscripted exponents like 107 cannot always be conveniently displayed, the letter E (or e ) is often used to represent “times ten raised to the power of” (which would be written as “× 10n”) and is followed by the value of the exponent; in other words, for any two real numbers m and n , the usage of "m En " would indicate a value of m × 10n. In this usage the character e is not related to the mathematical constant e or the exponential function e x (a confusion that is unlikely if scientific notation is represented by a capital E ). Although the E stands for exponent , the notation is usually referred to as (scientific) E notation rather than (scientific) exponential notation .

As an experiment- try rounding your result to the nearest seven decimal places and see what your result is
round(-4.371138828673793e-08, 7)

-0.0

1 Like

Ahhhh yeah, I’m the dumb one here. I don’t read scientific notation often so I completely forgot that number is basically zero. So, it’s working exactly as expected.

Thanks for taking the time to respond anyway. :slight_smile:

no worries, happens to everybody at some point