Is there a better way of finding the difference between 2 numbers?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Johnnyfantastic6

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

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?

Thomas Karcher | 2020-12-18 18:51

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

Ertain | 2020-12-18 19:18

:bust_in_silhouette: Reply From: Omicron

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))

this is exactly what I
was looking for, thanks!

Johnnyfantastic6 | 2020-12-18 19:22