Voldemort Voldemort - 5 months ago 7
Ruby Question

Arithmetic gives unexpected value in ruby

Why is this:

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


Giving me
-253
when it should be
38165
instead?

Answer

^ is the bitwise exclusive OR operator (XOR)

** is the exponent operator, use:

((256-438)**2)+((227-298)**2)
Comments