--- a/Float.st Sat Jun 26 21:07:59 2004 +0200
+++ b/Float.st Sat Jun 26 21:32:09 2004 +0200
@@ -1356,6 +1356,7 @@
OBJ s;
char *fmt;
char fmtBuffer[20];
+ int len;
if (__isString(@global(DefaultPrintFormat))) {
fmt = (char *) __stringVal(@global(DefaultPrintFormat));
@@ -1377,34 +1378,38 @@
strcat(fmtBuffer, "G");
#endif
- sprintf(buffer, fmtBuffer, __floatVal(self));
-
- /*
- * 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(DecimalPointCharacter))) {
- *cp++ = __intVal(_characterVal(@global(DecimalPointCharacter)));
+ __BEGIN_PROTECT_REGISTERS__
+ len = snprintf(buffer, sizeof(buffer), fmtBuffer, __floatVal(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(DecimalPointCharacter))) {
+ *cp++ = __intVal(__characterVal(@global(DecimalPointCharacter)));
+ } else {
+ *cp++ = '.';
+ }
+ *cp++ = '0';
+ *cp = '\0';
} else {
- *cp++ = '.';
- }
- *cp++ = '0';
- *cp = '\0';
- } else {
- if (cp && (*cp == '.')) {
- if (__isCharacter(@global(DecimalPointCharacter))) {
- *cp = __intVal(_characterVal(@global(DecimalPointCharacter)));
+ if (cp && (*cp == '.')) {
+ if (__isCharacter(@global(DecimalPointCharacter))) {
+ *cp = __intVal(__characterVal(@global(DecimalPointCharacter)));
+ }
}
}
- }
-
- s = __MKSTRING(buffer COMMA_SND);
- if (s != nil) {
- RETURN (s);
+
+ s = __MKSTRING(buffer);
+ if (s != nil) {
+ RETURN (s);
+ }
}
%}.
"
@@ -1427,13 +1432,12 @@
DecimalPointCharacter := $,.
1.234 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
+ 1.0 printString.
+ 1e10 printString.
+ 1.2e3 printString.
+ 1.2e30 printString.
+ (1.0 uncheckedDivide:0) printString.
+ (0.0 uncheckedDivide:0) printString.
DecimalPointCharacter := $.
"
!
@@ -1451,22 +1455,35 @@
%{ /* STACK: 400 */
char buffer[256];
OBJ s;
+ int len;
if (__isString(formatString)) {
- sprintf(buffer, __stringVal(formatString), __floatVal(self));
-
- s = __MKSTRING(buffer COMMA_SND);
+ /*
+ * actually only needed on sparc: since thisContext is
+ * in a global register, which gets destroyed by printf,
+ * manually save it here - very stupid ...
+ */
+ __BEGIN_PROTECT_REGISTERS__
+
+ len = snprintf(buffer, sizeof(buffer), __stringVal(formatString), __floatVal(self));
+
+ __END_PROTECT_REGISTERS__
+
+ if (len < 0) goto fail;
+
+ s = __MKSTRING_L(buffer, len);
if (s != nil) {
RETURN (s);
}
}
+fail: ;
%}.
self primitiveFailed
"
Float pi printfPrintString:'%%lg -> %lg'
Float pi printfPrintString:'%%lf -> %lf'
- Float pi printfPrintString:'%%7.5lg -> %7.5lg'
+ Float pi printfPrintString:'%%7.15lg -> %7.15lg'
Float pi printfPrintString:'%%7.5lf -> %7.5lf'
Float pi printfPrintString:'%%G -> %G'
Float pi printfPrintString:'%%F -> %F'
@@ -2494,7 +2511,7 @@
!Float class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.152 2004-04-07 10:19:44 werner Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.153 2004-06-26 19:31:38 stefan Exp $'
! !
Float initialize!