Define #abs
authorStefan Vogel <sv@exept.de>
Thu, 30 Oct 2003 16:06:08 +0100
changeset 7725 c3c9115bb492
parent 7724 1c8c8024c902
child 7726 a3bb3ae6c02e
Define #abs
ShortFloat.st
--- a/ShortFloat.st	Thu Oct 30 16:03:31 2003 +0100
+++ b/ShortFloat.st	Thu Oct 30 16:06:08 2003 +0100
@@ -580,6 +580,28 @@
     ^ aNumber quotientFromShortFloat:self
 !
 
+abs
+    "return the absolute value of the receiver
+     reimplemented here for speed"
+
+%{  /* NOCONTEXT */
+
+    OBJ newFloat;
+    float val = __shortFloatVal(self);
+
+    if (val < 0.0) {
+        __qMKSFLOAT(newFloat, -val);
+        RETURN ( newFloat );
+    }
+    RETURN (self);
+%}.
+
+    "
+     3.0 asShortFloat abs
+     -3.0 asShortFloat abs
+    "
+!
+
 negated
     "return myself negated"
 
@@ -1456,5 +1478,5 @@
 !ShortFloat class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/ShortFloat.st,v 1.81 2003-07-02 09:52:21 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ShortFloat.st,v 1.82 2003-10-30 15:06:08 stefan Exp $'
 ! !