--- a/Float.st Wed Mar 25 16:41:30 2015 +0100
+++ b/Float.st Wed Mar 25 16:41:40 2015 +0100
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
"
COPYRIGHT (c) 1988 by Claus Gittinger
All Rights Reserved
@@ -624,16 +622,24 @@
^ 2.7182818284590452353602874713526625
!
-emax
- "Answer the maximum exponent for this representation."
-
- ^1023
-!
-
-emin
- "Answer the minimum exponent for this representation."
-
- ^ -1022
+fmax
+ "The largest value allowed by the characterized
+ floating point object representation. The answer
+ should be equal to
+
+ (1 - (self radix raisedTo: self precision negated))
+ * (self radix raisedTo: self emax + 1)
+
+ Note the ANSI spec says
+
+ (1 - (self radix raisedTo: self precision negated))
+ * (self radix raisedTo: self emax)
+
+ but this is not correct."
+
+ ^(self fromNumber: 1) -
+ ((self fromNumber: self radix) timesTwoPower: self precision negated - 1) * self radix
+ * ((self fromNumber: self radix) timesTwoPower: self emax - 1)
!
ln2
@@ -1772,38 +1778,6 @@
LimitedPrecisonReal and its subclasses use #printString instead of
#printOn: as basic print mechanism."
- ^ self printStringWithFormat:DefaultPrintFormat
-
- "
- Float pi 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
- self pi printString.
-
- DecimalPointCharacter := $,.
- 1.234 printString.
- 1.0 printString.
- 1e10 printString.
- 1.2e3 printString.
- 1.2e30 printString.
- (1.0 uncheckedDivide:0) printString.
- (0.0 uncheckedDivide:0) printString.
- DecimalPointCharacter := $.
- "
-!
-
-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];
@@ -1813,13 +1787,13 @@
char fmtBuffer[20];
int len;
- if (__isStringLike(format)) {
- fmt = (char *) __stringVal(format);
+ if (__isStringLike(@global(DefaultPrintFormat))) {
+ fmt = (char *) __stringVal(@global(DefaultPrintFormat));
} else {
- /*
- * in case we get called with garbage ...
- */
- fmt = ".15";
+ /*
+ * in case we get called before #initialize ...
+ */
+ fmt = ".15";
}
/*
@@ -1838,33 +1812,33 @@
__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 == ',') || (*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 == '.') || (*cp == ','))) {
- if (__isCharacter(@global(DecimalPointCharacterForPrinting))) {
- *cp = __intVal(__characterVal(@global(DecimalPointCharacterForPrinting)));
- }
- }
- }
-
- s = __MKSTRING(buffer);
- if (s != nil) {
- RETURN (s);
- }
+ /*
+ * 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 == ',') || (*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 == '.') || (*cp == ','))) {
+ if (__isCharacter(@global(DecimalPointCharacterForPrinting))) {
+ *cp = __intVal(__characterVal(@global(DecimalPointCharacterForPrinting)));
+ }
+ }
+ }
+
+ s = __MKSTRING(buffer);
+ if (s != nil) {
+ RETURN (s);
+ }
}
%}.
"
@@ -1877,24 +1851,24 @@
^ ObjectMemory allocationFailureSignal raise.
"
- 1.0 printString
- 1.234 printString
- 1e10 printString
- 1.2e3 printString
- 1.2e30 printString
- (1.0 uncheckedDivide:0) printString
- (0.0 uncheckedDivide:0) printString
- self pi printString.
-
- DecimalPointCharacter := $,.
- 1.234 printString.
- 1.0 printString.
- 1e10 printString.
- 1.2e3 printString.
- 1.2e30 printString.
- (1.0 uncheckedDivide:0) printString.
- (0.0 uncheckedDivide:0) printString.
- DecimalPointCharacter := $.
+ 1.0 printString
+ 1.234 printString
+ 1e10 printString
+ 1.2e3 printString
+ 1.2e30 printString
+ (1.0 uncheckedDivide:0) printString
+ (0.0 uncheckedDivide:0) printString
+ self pi printString.
+
+ DecimalPointCharacter := $,.
+ 1.234 printString.
+ 1.0 printString.
+ 1e10 printString.
+ 1.2e3 printString.
+ 1.2e30 printString.
+ (1.0 uncheckedDivide:0) printString.
+ (0.0 uncheckedDivide:0) printString.
+ DecimalPointCharacter := $.
"
!
@@ -3134,11 +3108,11 @@
!Float class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.214 2015-03-25 19:18:10 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.211 2015-03-25 15:41:40 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.214 2015-03-25 19:18:10 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.211 2015-03-25 15:41:40 cg Exp $'
! !