diff -r 93d8a1a98244 -r c206b4711b6e ShortFloat.st --- a/ShortFloat.st Mon Jun 28 09:32:38 2004 +0200 +++ b/ShortFloat.st Tue Jun 29 15:20:35 2004 +0200 @@ -1001,6 +1001,82 @@ "ShortFloat pi printfPrintString:'%%F -> %F'" "ShortFloat pi printfPrintString:'%%7.5G -> %7.5G'" "ShortFloat 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; + + /* + * build a printf format string + */ + + __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 + __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 asShortFloat storeString + 1.234 asShortFloat storeString + 1e10 asShortFloat storeString + 1.2e3 asShortFloat storeString + 1.2e30 asShortFloat storeString + Float pi asShortFloat storeString + (1.0 uncheckedDivide:0) asShortFloat storeString + (0.0 uncheckedDivide:0) asShortFloat storeString + + DecimalPointCharacter := $,. + 1.234 asShortFloat storeString. + 1.0 asShortFloat storeString. + 1e10 asShortFloat storeString. + 1.2e3 asShortFloat storeString. + 1.2e30 asShortFloat storeString. + (1.0 uncheckedDivide:0) asShortFloat storeString. + (0.0 uncheckedDivide:0) asShortFloat storeString. + DecimalPointCharacter := $. + " ! ! !ShortFloat methodsFor:'special access'! @@ -1518,5 +1594,5 @@ !ShortFloat class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libbasic/ShortFloat.st,v 1.84 2004-06-26 19:39:00 stefan Exp $' + ^ '$Header: /cvs/stx/stx/libbasic/ShortFloat.st,v 1.85 2004-06-29 13:20:35 stefan Exp $' ! !