ArithmeticValue.st
changeset 22723 5e9e074b1c0f
parent 22358 101b2548022b
child 22731 3381d1e307c5
--- a/ArithmeticValue.st	Fri May 04 12:07:19 2018 +0200
+++ b/ArithmeticValue.st	Sat May 05 22:23:31 2018 +0200
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
 "
  COPYRIGHT (c) 1993 by Claus Gittinger
 	      All Rights Reserved
@@ -563,6 +565,24 @@
     ^ self
 !
 
+copySignTo:aNumber
+    "Return a number with same magnitude as aNumber and same sign as self"
+
+    (self negative == aNumber negative) ifTrue:[^ aNumber].
+    ^ aNumber negated
+
+    "
+     -15 copySignTo:1234  -> -1234
+     -15 copySignTo:-1234 -> -1234
+     15 copySignTo:1234   -> 1234
+     15 copySignTo:-1234  -> 1234
+     1.0 copySignTo:0.0   -> 0.0 
+     -1.0 copySignTo:0.0  -> -0.0
+     1 copySignTo:(1/3)   -> (1/3) 
+     -1 copySignTo:(1/3)  -> (-1/3)
+    "
+!
+
 dist:arg
     "return the distance between the arg and the receiver."