double dispatching
authorClaus Gittinger <cg@exept.de>
Sat, 21 Jun 2003 12:32:43 +0200
changeset 7441 17e37777f83b
parent 7440 d96bfc80e75e
child 7442 1b0a20747a64
double dispatching NaN, INF printString
Float.st
--- a/Float.st	Sat Jun 21 12:25:46 2003 +0200
+++ b/Float.st	Sat Jun 21 12:32:43 2003 +0200
@@ -250,20 +250,6 @@
 "
 ! !
 
-!Float class methodsFor:'initialization'!
-
-initialize
-    DefaultPrintFormat := '.6'  "/ 6 valid digits
-
-    "
-     DefaultPrintFormat := '.9'. 
-     Float pi printString.     
-
-     DefaultPrintFormat := '.6'. 
-     Float pi printString.     
-    "
-! !
-
 !Float class methodsFor:'instance creation'!
 
 basicNew
@@ -466,6 +452,20 @@
     ].
 ! !
 
+!Float class methodsFor:'class initialization'!
+
+initialize
+    DefaultPrintFormat := '.6'  "/ 6 valid digits
+
+    "
+     DefaultPrintFormat := '.9'. 
+     Float pi printString.     
+
+     DefaultPrintFormat := '.6'. 
+     Float pi printString.     
+    "
+! !
+
 !Float class methodsFor:'constants'!
 
 NaN
@@ -528,7 +528,6 @@
     "Modified: 23.4.1996 / 09:27:15 / cg"
 ! !
 
-
 !Float class methodsFor:'queries'!
 
 exponentCharacter
@@ -918,12 +917,13 @@
     |shifty sign expPart exp fraction fractionPart result zeroBitsCount|
 
     self isFinite ifFalse:[
-        ^ self class
-            raise:#conversionErrorSignal
-            receiver:self
-            selector:#asTrueFraction
-            arguments:#()
-            errorString:'Cannot represent non-finite float as a fraction'.
+        ^ self asMetaNumber
+"/        ^ self class
+"/            raise:#domainErrorSignal
+"/            receiver:self
+"/            selector:#asTrueFraction
+"/            arguments:#()
+"/            errorString:'Cannot represent non-finite float as a fraction'.
     ].
 
     "Extract the bits of an IEEE double float "
@@ -1158,7 +1158,6 @@
     ^ super ~= aNumber
 ! !
 
-
 !Float methodsFor:'mathematical functions'!
 
 exp
@@ -1361,12 +1360,12 @@
     char fmtBuffer[20];
 
     if (__isString(@global(DefaultPrintFormat))) {
-	fmt = (char *) __stringVal(@global(DefaultPrintFormat));
+        fmt = (char *) __stringVal(@global(DefaultPrintFormat));
     } else {
-	/*
-	 * in case we get called before #initialize ...
-	 */
-	fmt = ".6";
+        /*
+         * in case we get called before #initialize ...
+         */
+        fmt = ".6";
     }
 
     /*
@@ -1387,17 +1386,17 @@
      * (i.e. look if string contains '.' or 'e' and append '.0' if not)
      */
     for (cp = buffer; *cp; cp++) {
-	if ((*cp == '.') || (*cp == 'E') || (*cp == 'e')) break;
+        if ((*cp == '.') || (*cp == 'E') || (*cp == 'e')) break;
     }
-    if (! *cp) {
-	*cp++ = '.';
-	*cp++ = '0';
-	*cp = '\0';
+    if (!*cp && (cp[-1] >= '0') && (cp[-1] <= '9')) {
+        *cp++ = '.';
+        *cp++ = '0';
+        *cp = '\0';
     }
 
     s = __MKSTRING(buffer COMMA_SND);
     if (s != nil) {
-	RETURN (s);
+        RETURN (s);
     }
 %}.
     "
@@ -1410,15 +1409,14 @@
     ^ ObjectMemory allocationFailureSignal raise.
 
     "
-	1.0 printString
-	1.234 printString
-	1e10 printString
-	1.2e3 printString
-	1.2e30 printString
-	(1.0 uncheckedDivide:0) printString
-	(0.0 uncheckedDivide:0) printString
+        1.0 printString
+        1.234 printString
+        1e10 printString
+        1.2e3 printString
+        1.2e30 printString
+        (1.0 uncheckedDivide:0) printString
+        (0.0 uncheckedDivide:0) printString
     "
-
 !
 
 printfPrintString:formatString
@@ -1730,7 +1728,10 @@
 
 %{
 #if defined(i386) && defined(linux)
-    RETURN ((__ByteArrayInstPtr(self)->ba_element[sizeof(double)-1] == 128) ? true : false );
+    unsigned int biasedExponent;
+
+    biasedExponent = ((short *)(__ByteArrayInstPtr(self)->ba_element))[3] & 0xFF70;
+    RETURN ((biasedExponent == 0x8000) ? true : false );
 #endif
 %}.
     ^ super isNegativeZero
@@ -1738,6 +1739,8 @@
     "
      0.0 isNegativeZero     
      -0.0 isNegativeZero       
+     -1.0 isNegativeZero       
+     1.0 isNegativeZero       
     "
 !
 
@@ -2472,7 +2475,7 @@
 !Float class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.146 2003-06-18 14:58:20 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.147 2003-06-21 10:32:43 cg Exp $'
 ! !
 
 Float initialize!