0 votes

this is the code im trying to make better:

func get_difference_between(number_one, number_two):
if number_one < 0:
    number_one *= -1
if number_two < 0:
    number_two *= -1
if number_one > number_two:
    return number_one - number_two
else: return number_two - number_one
Godot version 3.2
in Engine by (36 points)

With this code, the difference between -5 and +6 is the same as between -5 and +4 ("1" in both cases). Is this really what you want?

Do you need the sign of the number? You can use the sign function to figure that out.

1 Answer

+2 votes
Best answer

what you are computing is absolute value of difference of their respective absolute value

if that is what you intend, then:

abs(abs(number_two)-abs(number_one))
by (336 points)
selected by

this is exactly what I
was looking for, thanks!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.