#BUGFIX by cg
authorClaus Gittinger <cg@exept.de>
Tue, 20 Jun 2017 15:38:43 +0200
changeset 21863 fca2a068f458
parent 21862 f5727dd0658a
child 21864 d2ad44002ad2
#BUGFIX by cg class: ZeroDivide changed: #defaultResumeValue fix: sign of infinity if proceeded
ZeroDivide.st
--- a/ZeroDivide.st	Tue Jun 20 14:16:02 2017 +0200
+++ b/ZeroDivide.st	Tue Jun 20 15:38:43 2017 +0200
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
 "
  COPYRIGHT (c) 2001 by eXept Software AG
               All Rights Reserved
@@ -41,6 +39,19 @@
 documentation
 "
     Raised when a division by zero is attempted.
+
+    To get the (in our oppinion: invalid) behavior of some programming languages such as JavaSript,
+    which do not report division by zero exceptions,
+    use the following code:
+    
+        ZeroDivide ignoreIn:[ x / 0.0 ] 
+
+    i.e.    
+        ZeroDivide ignoreIn:[ 1.0 / 0.0 ] 
+    returns +Inf,   
+    and
+        ZeroDivide ignoreIn:[ -1.0 / 0.0 ] 
+    returns -Inf instead.    
 "
 !
 
@@ -78,9 +89,14 @@
 !ZeroDivide methodsFor:'accessing'!
 
 defaultResumeValue
-    "return infinity here, if ever proceeded"
+    "return +/- infinity here, if ever proceeded"
 
-    ^ parameter receiver class infinity
+    |poorReceiver|
+    
+    (poorReceiver := self dividend) negative ifTrue:[
+        ^ poorReceiver class negativeInfinity
+    ].    
+    ^ poorReceiver class infinity
 
     "
      |a b|
@@ -98,7 +114,7 @@
     "
      |a b|
 
-     a := 5.0.
+     a := -5.0.
      b := 0.0.
      ZeroDivide handle:[:ex |
         Transcript showCR:('division by zero - dividend was: ' , ex dividend printString).
@@ -107,6 +123,8 @@
         a / b
      ]            
     "
+
+    "Modified: / 20-06-2017 / 15:37:59 / cg"
 !
 
 dividend