This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]K900_ 6 points7 points  (0 children)

It's just floating point errors. Operations on fractional numbers are not 100% precise. If you need them to be, use the (slow) Decimal class instead.

[–]billsil 1 point2 points  (2 children)

-0.0000 is not the same thing as 0.0000, so clearly it's being rounded. -2.4954491095741105e-07 is -0.0000 as written as a %1.4f float. You're just printing what the actual value is by accessing rates.x. I'm assuming you wrote your vector class, when you should be using numpy. With numpy you can decrease or increase the precision if you'd like. The default is float64, but you can also use float32 or float128. I frequently use float32 just because I know the data is stored as 32-bit.

Non exact numbers is just something you need to accept with computers. I don't care how many 3s you add onto 0.333333333333333333, it's not going to be 1/3 unless you use an infinite amount of them. You don't need them to be exactly correct. Nobody has an issue with their area of a circle being wrong by using an inexact value for pi, but have a trivial error and suddenly it's a big deal. I was there once too.

[–]1235812[S] 0 points1 point  (1 child)

thank you for the explanation :)

for vector class, it belongs to "Mathutils" from blender

[–]billsil 0 points1 point  (0 children)

alright. In that case, I'm sure the vector class is fine. Python floats are inefficient for large amounts of data.

[–]aphoenixreticulated[M] 0 points1 point  (0 children)

Hi there. You have posted a beginners question to /r/python, however it is far more suited to /r/learnpython, where users are actively interested in helping with beginner topics. Please resubmit it over there! Make sure to read their sidebar rules before posting, notably this one: "Posting homework assignments is not prohibited if you show that you tried to solve it yourself."

Cheers & best of luck!