ShortFloat.st
branchjv
changeset 17765 e3ee4a675abc
parent 17761 b0e5971141bc
child 17767 a4a32df3aa5e
--- a/ShortFloat.st	Thu May 06 12:27:45 2010 +0100
+++ b/ShortFloat.st	Tue May 18 14:31:21 2010 +0100
@@ -322,6 +322,14 @@
     "Modified: / 7.1.1998 / 16:17:59 / cg"
 ! !
 
+!ShortFloat class methodsFor:'accessing'!
+
+defaultPrintFormat
+    "this is fixed in ShortFloat"
+
+    ^ '.6'
+! !
+
 !ShortFloat class methodsFor:'binary storage'!
 
 readBinaryIEEESingleFrom:aStream
@@ -940,65 +948,60 @@
      * manually save it here - very stupid ...
      */
     __BEGIN_PROTECT_REGISTERS__
-
-#ifdef SYSV
-    len = snprintf(buffer, sizeof(buffer), "%.6lg", (double)__shortFloatVal(self));
-#else
-    len = snprintf(buffer, sizeof(buffer), "%.6G", (double)__shortFloatVal(self));
-#endif
-
+    len = snprintf(buffer, sizeof(buffer), "%.6g", (float)__shortFloatVal(self));
     __END_PROTECT_REGISTERS__
 
     if (len >= 0 && len <= sizeof(buffer)-3) {
-	/*
-	 * kludge to make integral float f prints as "f.0" (not as "f" as printf does)
-	 * (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[-1] >= '0') && (cp[-1] <= '9')) {
-	    if (__isCharacter(@global(DecimalPointCharacterForPrinting))) {
-		*cp++ = __intVal(__characterVal(@global(DecimalPointCharacterForPrinting)));
-	    } else {
-		*cp++ = '.';
-	    }
-	    *cp++ = '0';
-	    *cp = '\0';
-	} else {
-	    if (cp && (*cp == '.')) {
-		if (__isCharacter(@global(DecimalPointCharacterForPrinting))) {
-		    *cp = __intVal(__characterVal(@global(DecimalPointCharacterForPrinting)));
-		}
-	    }
-	}
+        /*
+         * kludge to make integral float f prints as "f.0" (not as "f" as printf does)
+         * (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[-1] >= '0') && (cp[-1] <= '9')) {
+            if (__isCharacter(@global(DecimalPointCharacterForPrinting))) {
+                *cp++ = __intVal(__characterVal(@global(DecimalPointCharacterForPrinting)));
+            } else {
+                *cp++ = '.';
+            }
+            *cp++ = '0';
+            *cp = '\0';
+        } else {
+            if (cp && (*cp == '.')) {
+                if (__isCharacter(@global(DecimalPointCharacterForPrinting))) {
+                    *cp = __intVal(__characterVal(@global(DecimalPointCharacterForPrinting)));
+                }
+            }
+        }
 
-	s = __MKSTRING(buffer);
-	if (s != nil) {
-	    RETURN (s);
-	}
+        s = __MKSTRING(buffer);
+        if (s != nil) {
+            RETURN (s);
+        }
     }
 %}.
     ^ self asFloat printString
 
     "
-	1.234 asShortFloat printString.
-	1.0 asShortFloat printString.
-	1e10 asShortFloat printString.
-	1.2e3 asShortFloat printString.
-	1.2e30 asShortFloat printString.
-	(1.0 uncheckedDivide:0) asShortFloat printString.
-	(0.0 uncheckedDivide:0) asShortFloat printString.
+        1.234 asShortFloat printString.
+        1.0 asShortFloat printString.
+        1e10 asShortFloat printString.
+        1.2e3 asShortFloat printString.
+        1.2e30 asShortFloat printString.
+        (1.0 uncheckedDivide:0) asShortFloat printString.
+        (0.0 uncheckedDivide:0) asShortFloat printString.
+        self pi printString.
 
-	DecimalPointCharacterForPrinting := $,.
-	1.234 asShortFloat printString.
-	1.0 asShortFloat printString.
-	1e10 asShortFloat printString.
-	1.2e3 asShortFloat printString.
-	1.2e30 asShortFloat printString.
-	(1.0 uncheckedDivide:0) asShortFloat printString.
-	(0.0 uncheckedDivide:0) asShortFloat printString.
-	DecimalPointCharacterForPrinting := $.
+        DecimalPointCharacterForPrinting := $,.
+        1.234 asShortFloat printString.
+        1.0 asShortFloat printString.
+        1e10 asShortFloat printString.
+        1.2e3 asShortFloat printString.
+        1.2e30 asShortFloat printString.
+        (1.0 uncheckedDivide:0) asShortFloat printString.
+        (0.0 uncheckedDivide:0) asShortFloat printString.
+        DecimalPointCharacterForPrinting := $.
     "
 !
 
@@ -1721,13 +1724,14 @@
 !ShortFloat class methodsFor:'documentation'!
 
 version
-    ^ '$Id: ShortFloat.st 10517 2010-04-26 18:26:38Z vranyj1 $'
+    ^ '$Id: ShortFloat.st 10523 2010-05-18 13:31:21Z vranyj1 $'
 !
 
 version_CVS
-    ^ '§Header: /cvs/stx/stx/libbasic/ShortFloat.st,v 1.103 2009/12/18 14:41:46 cg Exp §'
+    ^ 'Header: /cvs/stx/stx/libbasic/ShortFloat.st,v 1.104 2010/05/05 13:56:55 stefan Exp §'
 !
 
 version_SVN
-    ^ '$Id: ShortFloat.st 10517 2010-04-26 18:26:38Z vranyj1 $'
+    ^ '$Id: ShortFloat.st 10523 2010-05-18 13:31:21Z vranyj1 $'
 ! !
+