Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Arithmetic gives unexpected value in ruby

Tags:

math

ruby

Why is this:

((256-438)^2)+((227-298)^2)

Giving me -253 when it should be 38165 instead?

like image 330
Voldemort Avatar asked Nov 27 '22 18:11

Voldemort


1 Answers

^ is the bitwise exclusive OR operator (XOR)

** is the exponent operator, use:

((256-438)**2)+((227-298)**2)
like image 119
Paul Creasey Avatar answered Nov 30 '22 08:11

Paul Creasey