in scala, given the integers d
& x
, I would have a boolean expression which should be true if and only if y = (x^2 - 1) / d^2
is a square.
I tried this:
(Math.sqrt((x * x - 1) / (d * d)).toInt * Math.sqrt((x * x - 1) / (d * d)).toInt == ((x * x - 1) / (d * d)))
but the 3-tuple (x = 2, d = <all values tested>, y = 0.0)
seems to be always an answer of my problem, which is obviously wrong.
I think my error comes from the rounding made: if x=2, d=4 (for example) then x * x - 1 == 3
and d * d == 16
so the division leads to 0
.
do you know what is the good expression?