New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vector.distance method: math domain error #5238
Comments
Use ** .5 to calculate the square root instead of math.sqrt() to avoid ValueError: math domain error which causes the app to crash. Issue source: kivy#5238
Doesn't it raise the error because of passing in a negative number? I mean, it all works for me with
Maybe we should just round the numbers correctly instead of allowing the possibility of having complex numbers passed into an IF statement? Edit: Also, maybe try to reproduce the same thing on some other machine? In any case, this seems to me rather as a CPython issue instead of our side i.e. some broken(or perhaps even fixed recently?) float math? |
Yeah I agree rounding the numbers is a much better idea, however, I was having issues with even small rounded decimal numbers such as this:
Can you reproduce this on your machine? |
I installed the 3.6.1(32bit) interpreter from scratch: >>> from math import sqrt
>>> sqrt(.1)
0.31622776601683794 >>> import math
>>> x2 = 0.48125; x1 = 0.48; y2 = 0.4716666666666667; y1 = 0.475
>>> print(math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2))
0.0035600015605489494 Win 8.1 64bit though |
Oh okay that is very strange... I am guessing it is just my machine then. I doubt it is because of Windows 10? |
Try maybe the other 3.6.1 version (64/32 alternative) if it's the same or try to reproduce it on some other machine (preferably with the same specs or at least some win10 with your updates). I believe 3.5.2 was compiled with GCC, so you'll need to try something with MSVC instead (official Python windows builds, not Win+ubuntu). |
Hey there! We're automatically closing this issue since the original poster (or another commenter) hasn't yet responded to the question or request made to them 14 days ago. We therefore assume that the user has lost interest or resolved the problem on their own. Closed issues that remain inactive for a long period may get automatically locked. Don't worry though; if this is in error, let us know with a comment and we'll be happy to reopen the issue. Thanks! (Please note that this is an automated comment.) |
Versions
Description
The app will crash when rapidly clicking around inside of the window. I tracked down the issue. It is with the
Vector.distance()
function when the distance is calculated. The issue is themath.sqrt()
function.I had the distance method print the values that were causing the error. They are different everytime.
These values will cause the
math.sqrt()
function to throw theValueError: math domain error
exception:For some reason the
math.sqrt()
function is unable to handle these inputs.Steps to Reproduce:
Code and Logs
Code:
Traceback:
The text was updated successfully, but these errors were encountered: