signals vs. errors
authorClaus Gittinger <cg@exept.de>
Tue, 17 Jun 2003 16:11:23 +0200
changeset 7403 857702a5a921
parent 7402 b9d45ce2463a
child 7404 670c6dee957f
signals vs. errors
ArithmeticValue.st
Float.st
Fraction.st
Integer.st
LimitedPrecisionReal.st
LongFloat.st
ShortFloat.st
--- a/ArithmeticValue.st	Tue Jun 17 16:08:21 2003 +0200
+++ b/ArithmeticValue.st	Tue Jun 17 16:11:23 2003 +0200
@@ -98,35 +98,49 @@
 arithmeticSignal
     "return the parent of all arithmetic signals"
 
-    ^ ArithmeticSignal
+    ^ ArithmeticError
 !
 
 conversionErrorSignal
     "return the signal which is raised when a conversion fails
-     (such as bcd decoding of an invalid BCD number)"
+     (such as when a NaN is to be converted)"
+
+    ^ ConversionError
 
-    ^ ConversionErrorSignal
-
-    "Created: / 15.11.1999 / 20:34:18 / cg"
+    "
+     ConversionError handle:[:ex |
+        Transcript flash
+     ]
+     do:[
+        (0.0 uncheckedDivide:0.0) asFraction
+     ]
+    "
 !
 
 divisionByZeroSignal
     "return the signal which is raised on division by zero"
 
-    ^ DivisionByZeroSignal
+    ^ ZeroDivide
 !
 
 domainErrorSignal
     "return the signal which is raised on math errors
      (such as log of 0 etc.)"
 
-    ^ DomainErrorSignal
+    ^ DomainError
+!
+
+imaginaryResultSignal
+    "return the signal which is raised when an imaginary result would be created
+     (such as when taking the sqrt of a negative number)"
+
+    ^ ImaginaryResultError
 !
 
 overflowSignal
     "return the signal which is raised on overflow conditions (in floats)"
 
-    ^ OverflowSignal
+    ^ OverflowError
 !
 
 rangeErrorSignal
@@ -138,14 +152,14 @@
 underflowSignal
     "return the signal which is raised on underflow conditions (in floats)"
 
-    ^ UnderflowSignal
+    ^ UnderflowError
 !
 
 unorderedSignal
     "return the signal which is raised when numbers are compared, 
      for which no ordering is defined (for example: complex numbers)"
 
-    ^ UnorderedSignal
+    ^ UnorderedNumbersError
 ! !
 
 !ArithmeticValue methodsFor:'arithmetic'!
@@ -1226,7 +1240,7 @@
 !ArithmeticValue class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/ArithmeticValue.st,v 1.53 2003-06-17 13:34:50 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ArithmeticValue.st,v 1.54 2003-06-17 14:08:50 cg Exp $'
 ! !
 
 ArithmeticValue initialize!
--- a/Float.st	Tue Jun 17 16:08:21 2003 +0200
+++ b/Float.st	Tue Jun 17 16:11:23 2003 +0200
@@ -1291,11 +1291,11 @@
     }
 %}.
     ^ self class
-        raise:#domainErrorSignal
+        raise:#imaginaryResultSignal
         receiver:self
         selector:#sqrt
         arguments:#()
-        errorString:'bad receiver in sqrt'
+        errorString:'bad (negative) receiver in sqrt'
 
     "
      10 sqrt
@@ -2299,11 +2299,18 @@
 
     __threadErrno = 0;
     frac = modf(__floatVal(self), &trunc);
-    if (__threadErrno == 0) {
-        RETURN (__MKFLOAT(frac));
+    if (! isnan(frac)) { 
+        if (__threadErrno == 0) {
+            RETURN (__MKFLOAT(frac));
+        }
     }
 %}.
-    ^ self primitiveFailed
+    ^ self class
+        raise:#domainErrorSignal
+        receiver:self
+        selector:#fractionPart
+        arguments:#()
+        errorString:'bad receiver in fractionPart'
 
     "
      1.6 fractionPart + 1.6 truncated    
@@ -2459,7 +2466,7 @@
 !Float class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.139 2003-06-17 12:06:29 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.140 2003-06-17 14:09:24 cg Exp $'
 ! !
 
 Float initialize!
--- a/Fraction.st	Tue Jun 17 16:08:21 2003 +0200
+++ b/Fraction.st	Tue Jun 17 16:11:23 2003 +0200
@@ -967,7 +967,6 @@
         ^ self
     ].
     ^ (numerator rem: denominator) / denominator
-    "/ ^ super fractionPart
 
     "
      (3/2) fractionPart + (3/2) truncated    
@@ -1048,7 +1047,7 @@
 !Fraction class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Fraction.st,v 1.64 2003-06-17 08:41:33 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Fraction.st,v 1.65 2003-06-17 14:09:33 cg Exp $'
 ! !
 
 Fraction initialize!
--- a/Integer.st	Tue Jun 17 16:08:21 2003 +0200
+++ b/Integer.st	Tue Jun 17 16:11:23 2003 +0200
@@ -77,7 +77,7 @@
 
 initialize
     BCDConversionErrorSignal isNil ifTrue:[
-        BCDConversionErrorSignal := ConversionErrorSignal newSignal.
+        BCDConversionErrorSignal := ConversionError newSignal.
         BCDConversionErrorSignal nameClass:self message:#bcdConversionErrorSignal.
         BCDConversionErrorSignal notifierString:'bcd conversion error'.
     ].
@@ -3217,7 +3217,7 @@
 !Integer class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Integer.st,v 1.159 2003-06-16 09:16:27 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Integer.st,v 1.160 2003-06-17 14:09:51 cg Exp $'
 ! !
 
 Integer initialize!
--- a/LimitedPrecisionReal.st	Tue Jun 17 16:08:21 2003 +0200
+++ b/LimitedPrecisionReal.st	Tue Jun 17 16:11:23 2003 +0200
@@ -423,7 +423,7 @@
 
     self isNaN ifTrue:[
         ^ self class
-            raise:#domainErrorSignal
+            raise:#conversionErrorSignal
             receiver:self
             selector:#asInteger
             arguments:#()
@@ -936,7 +936,7 @@
 !LimitedPrecisionReal class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/LimitedPrecisionReal.st,v 1.52 2003-06-17 13:19:15 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/LimitedPrecisionReal.st,v 1.53 2003-06-17 14:10:40 cg Exp $'
 ! !
 
 LimitedPrecisionReal initialize!
--- a/LongFloat.st	Tue Jun 17 16:08:21 2003 +0200
+++ b/LongFloat.st	Tue Jun 17 16:11:23 2003 +0200
@@ -1154,11 +1154,11 @@
     ].
 
     ^ self class
-        raise:#domainErrorSignal
+        raise:#imaginaryResultSignal
         receiver:self
         selector:#sqrt
         arguments:#()
-        errorString:'bad receiver in sqrt'
+        errorString:'bad (negative) receiver in sqrt'
 
     "
      10 asLongFloat sqrt
@@ -2147,7 +2147,7 @@
 !LongFloat class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/LongFloat.st,v 1.34 2003-06-17 13:08:37 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/LongFloat.st,v 1.35 2003-06-17 14:11:14 cg Exp $'
 ! !
 
 LongFloat initialize!
--- a/ShortFloat.st	Tue Jun 17 16:08:21 2003 +0200
+++ b/ShortFloat.st	Tue Jun 17 16:11:23 2003 +0200
@@ -1282,11 +1282,18 @@
 
     __threadErrno = 0;
     frac = modf((double)(__shortFloatVal(self)), &trunc);
-    if (__threadErrno == 0) {
-        RETURN (__MKSFLOAT((float)frac));
+    if (! isnan(frac)) { 
+        if (__threadErrno == 0) {
+            RETURN (__MKSFLOAT((float)frac));
+        }
     }
 %}.
-    ^ self primitiveFailed
+    ^ self class
+        raise:#domainErrorSignal
+        receiver:self
+        selector:#fractionPart
+        arguments:#()
+        errorString:'bad receiver in fractionPart'
 
     "
      1.6 asShortFloat fractionPart + 1.6 asShortFloat truncated    
@@ -1468,5 +1475,5 @@
 !ShortFloat class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/ShortFloat.st,v 1.74 2003-06-17 11:53:05 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ShortFloat.st,v 1.75 2003-06-17 14:11:23 cg Exp $'
 ! !