Float.st
changeset 8422 c206b4711b6e
parent 8417 dcba76518224
child 8635 38674ba49a14
--- a/Float.st	Mon Jun 28 09:32:38 2004 +0200
+++ b/Float.st	Tue Jun 29 15:20:35 2004 +0200
@@ -1490,6 +1490,78 @@
      Float pi printfPrintString:'%%7.5G -> %7.5G'
      Float pi printfPrintString:'%%7.5F -> %7.5F'
     "
+!
+
+storeString
+    "return a printed representation of the receiver;
+     all valid digits are printed.
+     LimitedPrecisonReal and its subclasses use #storeString instead of
+     #storeOn: as basic print mechanism."
+
+%{  /* NOCONTEXT */
+
+    char buffer[64];
+    REGISTER char *cp;
+    OBJ s;
+    int len;
+
+    __BEGIN_PROTECT_REGISTERS__
+#ifdef SYSV
+    len = snprintf(buffer, sizeof(buffer), "%.14lg", __floatVal(self));
+#else
+    len = snprintf(buffer, sizeof(buffer), "%.14G", __floatVal(self));
+#endif
+    __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')) {
+            *cp++ = '.';
+            *cp++ = '0';
+            *cp = '\0';
+        } 
+
+        s = __MKSTRING(buffer);
+        if (s != nil) {
+            RETURN (s);
+        }
+    }
+%}.
+    "
+     memory allocation (for the new string) failed.
+     When we arrive here, there was no memory, even after a garbage collect.
+     This means, that the VM wanted to get some more memory from the
+     OS, which was not kind enough to give it.
+     Bad luck - you should increase the swap space on your machine.
+    "
+    ^ ObjectMemory allocationFailureSignal raise.
+
+    "
+        1.0 storeString
+        1.234 storeString
+        1e10 storeString
+        1.2e3 storeString
+        1.2e30 storeString
+        Float pi storeString
+        (1.0 uncheckedDivide:0) storeString
+        (0.0 uncheckedDivide:0) storeString
+
+        DecimalPointCharacter := $,.
+        1.234 storeString. 
+        1.0 storeString.    
+        1e10 storeString.   
+        1.2e3 storeString.  
+        1.2e30 storeString. 
+        (1.0 uncheckedDivide:0) storeString.    
+        (0.0 uncheckedDivide:0) storeString.
+        DecimalPointCharacter := $. 
+    "
 ! !
 
 !Float methodsFor:'private-accessing'!
@@ -2511,7 +2583,7 @@
 !Float class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.153 2004-06-26 19:31:38 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.154 2004-06-29 13:20:33 stefan Exp $'
 ! !
 
 Float initialize!