Number.st
branchjv
changeset 19137 199b5e15b1da
parent 19103 71257a47eba2
parent 19136 5645cf0c4774
child 19142 ff3923c6ad38
--- a/Number.st	Thu Jan 28 14:59:07 2016 +0000
+++ b/Number.st	Tue Feb 02 07:03:45 2016 +0100
@@ -2389,6 +2389,25 @@
     ^ true
 !
 
+isPerfectSquare
+    "return true if I am a perfect square.
+     That is a number for which the square root is an integer."
+
+    self truncated = self ifFalse:[^ false].
+    ^ self asInteger isPerfectSquare
+
+    "
+     0 isPerfectSquare
+     0.0 isPerfectSquare
+     3 isPerfectSquare
+     3.0 isPerfectSquare
+     4 isPerfectSquare
+     4.0 isPerfectSquare
+     9 isPerfectSquare
+     9.0 isPerfectSquare
+    "
+!
+
 isReal
     "return true, if the receiver is some kind of real number (as opposed to a complex);
      true is returned here - the method is redefined from Object."