what's the way to determine if an Int a perfect square in Haskell?
Posted
by valya
on Stack Overflow
See other posts from Stack Overflow
or by valya
Published on 2010-05-11T02:23:18Z
Indexed on
2010/05/11
2:44 UTC
Read the original article
Hit count: 304
I need a simple function
is_square :: Int -> Bool
which determines if an Int N a perfect square (is there an integer x such that x*x = N).
Of course I can just write something like
is_square n = sq * sq == n
where sq = floor $ sqrt $ (fromIntegral n::Double)
but it looks terrible! Maybe there is a common simple way to implement such predicate?
© Stack Overflow or respective owner