--- a/ShortFloat.st Wed Mar 25 20:18:10 2015 +0100
+++ b/ShortFloat.st Wed Mar 25 20:18:18 2015 +0100
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
"
COPYRIGHT (c) 1996 by Claus Gittinger
All Rights Reserved
@@ -1207,6 +1205,42 @@
LimitedPrecisonReal and its subclasses use #printString instead of
#printOn: as basic print mechanism."
+ ^ self printStringWithFormat:DefaultPrintFormat
+
+ "
+ 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.
+
+ self pi printString.
+ DefaultPrintFormat := '.3'.
+ self pi printString.
+ DefaultPrintFormat := '.7'.
+
+ 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 := $.
+ "
+!
+
+printStringWithFormat:format
+ "return a printed representation of the receiver;
+ fmt must be of the form: .nn, where nn is the number of digits.
+ To print 6 valid digits, use printStringWithFormat:'.6'
+ For Floats, the default used in printString, is 15 (because its a double);
+ for ShortFloats, it is 6 (because it is a float)"
+
%{ /* NOCONTEXT */
char buffer[64];
@@ -1216,11 +1250,11 @@
char *fmt;
char fmtBuffer[20];
- if (__isStringLike(@global(DefaultPrintFormat))) {
- fmt = (char *) __stringVal(@global(DefaultPrintFormat));
+ if (__isStringLike(format)) {
+ fmt = (char *) __stringVal(format);
} else {
/*
- * in case we get called before #initialize ...
+ * in case we get called with garbage...
*/
fmt = ".7";
}
@@ -1274,8 +1308,9 @@
^ self asFloat printString
"
- 1.234 asShortFloat printString.
- 1.0 asShortFloat printString.
+ 1.234 asShortFloat printString.
+ ShortFloat pi printString.
+ 1.0 asShortFloat printString.
1e10 asShortFloat printString.
1.2e3 asShortFloat printString.
1.2e30 asShortFloat printString.
@@ -2063,11 +2098,11 @@
!ShortFloat class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/ShortFloat.st,v 1.139 2015-03-25 17:53:43 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/ShortFloat.st,v 1.140 2015-03-25 19:18:18 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic/ShortFloat.st,v 1.139 2015-03-25 17:53:43 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/ShortFloat.st,v 1.140 2015-03-25 19:18:18 cg Exp $'
! !