Float.st
changeset 14672 8abd84f0951a
parent 14630 c84d8830c33e
child 14689 f709732040c1
--- a/Float.st	Fri Jan 18 21:56:20 2013 +0100
+++ b/Float.st	Sat Jan 19 16:49:30 2013 +0100
@@ -38,6 +38,10 @@
  extern errno;
 #endif
 
+#if !defined (WIN32)
+# include <locale.h>
+#endif
+
 #if defined (_AIX)
 # include <float.h>
 #endif
@@ -284,15 +288,15 @@
 
 %{   /* NOCONTEXT */
      if (__isStringLike(aString) && __isSmallInteger(startIndex)) {
-        char *cp = (char *)(__stringVal(aString));
-        int idx = __intVal(startIndex) - 1;
-        double atof();
-        double val;
-
-        if ((unsigned)idx < __stringSize(aString)) {
-            val = atof(cp + idx);
-            RETURN (__MKFLOAT(val));
-        }
+	char *cp = (char *)(__stringVal(aString));
+	int idx = __intVal(startIndex) - 1;
+	double atof();
+	double val;
+
+	if ((unsigned)idx < __stringSize(aString)) {
+	    val = atof(cp + idx);
+	    RETURN (__MKFLOAT(val));
+	}
      }
 %}.
      self primitiveFailed.
@@ -312,17 +316,17 @@
      Float fastFromString:'hello123.45E4' at:1
 
      Time millisecondsToRun:[
-        100000 timesRepeat:[
-            Float readFrom:'123.45'
-        ]
+	100000 timesRepeat:[
+	    Float readFrom:'123.45'
+	]
      ]
     "
 
     "
      Time millisecondsToRun:[
-        100000 timesRepeat:[
-            Float fastFromString:'123.45' at:1
-        ]
+	100000 timesRepeat:[
+	    Float fastFromString:'123.45' at:1
+	]
      ]
     "
 !
@@ -371,7 +375,7 @@
 
     num := super readFrom:aStringOrStream onError:nil.
     num isNil ifTrue:[
-        ^ exceptionBlock value
+	^ exceptionBlock value
     ].
     ^ num asFloat
 
@@ -471,16 +475,16 @@
 
 initialize
     Pi isNil ifTrue:[
-        DefaultPrintFormat := '.15'.  "/ print 15 valid digits
-        Pi := 3.14159265358979323846264338327950288419716939937510582097494459.
-        Halfpi := Pi / 2.0.
-        HalfpiNegative := Halfpi negated.
-        Twopi := Pi * 2.0.
-        E := 2.7182818284590452353602874713526625.
-        Sqrt2 := 1.41421356237309504880168872420969808.
-        RadiansPerDegree := Pi / 180.0.
-        Ln2 := 0.69314718055994530941723212145817657.
-        Ln10 := 10.0 ln.
+	DefaultPrintFormat := '.15'.  "/ print 15 valid digits
+	Pi := 3.14159265358979323846264338327950288419716939937510582097494459.
+	Halfpi := Pi / 2.0.
+	HalfpiNegative := Halfpi negated.
+	Twopi := Pi * 2.0.
+	E := 2.7182818284590452353602874713526625.
+	Sqrt2 := 1.41421356237309504880168872420969808.
+	RadiansPerDegree := Pi / 180.0.
+	Ln2 := 0.69314718055994530941723212145817657.
+	Ln10 := 10.0 ln.
     ].
 
     "
@@ -594,7 +598,7 @@
 %}
 
     "
-        self getFPUControl
+	self getFPUControl
     "
 !
 
@@ -613,7 +617,7 @@
 %}
 
     "
-        self setFPUControl
+	self setFPUControl
     "
 ! !
 
@@ -1374,26 +1378,26 @@
     if (val > 0.0)
 #endif
     {
-        __threadErrno = 0;
-        rslt = log10(val);
-        if (! isnan(rslt))  /* Currently all our systems support isnan() */
-        {
-            if (__threadErrno == 0) {
-                __qMKFLOAT(newFloat, rslt);
-                RETURN ( newFloat );
-            }
-        }
+	__threadErrno = 0;
+	rslt = log10(val);
+	if (! isnan(rslt))  /* Currently all our systems support isnan() */
+	{
+	    if (__threadErrno == 0) {
+		__qMKFLOAT(newFloat, rslt);
+		RETURN ( newFloat );
+	    }
+	}
     }
 %}.
     "
      an invalid value for logarithm
     "
     ^ self class
-        raise:#domainErrorSignal
-        receiver:self
-        selector:#log10
-        arguments:#()
-        errorString:'bad receiver in log10'
+	raise:#domainErrorSignal
+	receiver:self
+	selector:#log10
+	arguments:#()
+	errorString:'bad receiver in log10'
 
     "Modified: / 16.11.2001 / 14:14:33 / cg"
 !
@@ -1494,12 +1498,12 @@
     int len;
 
     if (__isStringLike(@global(DefaultPrintFormat))) {
-        fmt = (char *) __stringVal(@global(DefaultPrintFormat));
+	fmt = (char *) __stringVal(@global(DefaultPrintFormat));
     } else {
-        /*
-         * in case we get called before #initialize ...
-         */
-        fmt = ".15";
+	/*
+	 * in case we get called before #initialize ...
+	 */
+	fmt = ".15";
     }
 
     /*
@@ -1518,33 +1522,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);
+	}
     }
 %}.
     "
@@ -1557,24 +1561,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 := $.
     "
 !
 
@@ -1597,23 +1601,23 @@
     int len;
 
     if (__isStringLike(formatString)) {
-        /*
-         * 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);
-        }
+	/*
+	 * 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: ;
 %}.
@@ -1653,23 +1657,23 @@
     __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')) {
-            *cp++ = '.';
-            *cp++ = '0';
-            *cp = '\0';
-        }
-
-        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')) {
+	    *cp++ = '.';
+	    *cp++ = '0';
+	    *cp = '\0';
+	}
+
+	s = __MKSTRING(buffer);
+	if (s != nil) {
+	    RETURN (s);
+	}
     }
 %}.
     "
@@ -1682,26 +1686,26 @@
     ^ 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
+	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
 
      notice that the storeString is NOT affected by DecimalPointCharacterForPrinting:
 
-        DecimalPointCharacterForPrinting := $,.
-        1.234 storeString.
-        1.0 storeString.
-        1e10 storeString.
-        1.2e3 storeString.
-        1.2e30 storeString.
-        (1.0 uncheckedDivide:0) storeString.
-        (0.0 uncheckedDivide:0) storeString.
-        DecimalPointCharacterForPrinting := $.
+	DecimalPointCharacterForPrinting := $,.
+	1.234 storeString.
+	1.0 storeString.
+	1e10 storeString.
+	1.2e3 storeString.
+	1.2e30 storeString.
+	(1.0 uncheckedDivide:0) storeString.
+	(0.0 uncheckedDivide:0) storeString.
+	DecimalPointCharacterForPrinting := $.
     "
 ! !
 
@@ -1829,20 +1833,20 @@
     __threadErrno = 0;
     frac = frexp(__floatVal(self), &exp);
     if (__threadErrno == 0) {
-        RETURN (__mkSmallInteger(exp));
+	RETURN (__mkSmallInteger(exp));
     }
 %}.
     ^ self primitiveFailed
 
     "
-     1.0 exponent  
-     2.0 exponent  
-     3.0 exponent  
-     4.0 exponent  
-     0.5 exponent  
-     0.4 exponent   
-     0.25 exponent  
-     0.2 exponent   
+     1.0 exponent
+     2.0 exponent
+     3.0 exponent
+     4.0 exponent
+     0.5 exponent
+     0.4 exponent
+     0.25 exponent
+     0.2 exponent
      0.00000011111 exponent
     "
 !
@@ -2778,11 +2782,11 @@
 !Float class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.182 2013-01-04 15:36:58 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.183 2013-01-19 15:49:30 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.182 2013-01-04 15:36:58 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.183 2013-01-19 15:49:30 cg Exp $'
 ! !