#FEATURE by exept
authorClaus Gittinger <cg@exept.de>
Mon, 25 Nov 2019 12:14:22 +0100
changeset 24974 58dffe3baf29
parent 24973 514048473232
child 24975 fdf3a5b2f6b6
#FEATURE by exept class: Float comment/format in: #ldexp: class: Float class changed: #fastFromString:at:
Float.st
--- a/Float.st	Mon Nov 25 12:14:09 2019 +0100
+++ b/Float.st	Mon Nov 25 12:14:22 2019 +0100
@@ -320,16 +320,21 @@
      int idx = __intVal(startIndex) - 1;
 
      if (__isStringLike(aString) && __isSmallInteger(startIndex)) {
-	char *cp = (char *)(__stringVal(aString));
-	double atof();
-	double val;
-	OBJ newFloat;
-
-	if ((unsigned)idx < __stringSize(aString)) {
-	    val = atof(cp + idx);
-	    __qMKFLOAT(newFloat, val);
-	    RETURN (newFloat);
-	}
+        char *cp = (char *)(__stringVal(aString));
+        double val;
+        OBJ newFloat;
+
+        if ((unsigned)idx < __stringSize(aString)) {
+#ifndef NO_STRTOD
+            double strtod(const char *, char**);
+            val = strtod(cp+idx, NULL);
+#else
+            double atof();
+            val = atof(cp + idx);
+#endif
+            __qMKFLOAT(newFloat, val);
+            RETURN (newFloat);
+        }
      }
 %}.
      self primitiveFailed.
@@ -363,17 +368,17 @@
 
     "
      Time millisecondsToRun:[
-	1000000 timesRepeat:[
-	    Float readFrom:'123.45'
-	]
+        1000000 timesRepeat:[
+            Float readFrom:'123.45'
+        ]
      ]
     "
 
     "
      Time millisecondsToRun:[
-	1000000 timesRepeat:[
-	    Float fastFromString:'123.45' at:1
-	]
+        1000000 timesRepeat:[
+            Float fastFromString:'123.45' at:1
+        ]
      ]
     "
 
@@ -1977,7 +1982,9 @@
 
 ldexp:exp
     "multiply the receiver by an integral power of 2.
-     I.e. return self * (2 ^ exp)"
+     I.e. return self * (2 ^ exp).
+     This is also the operation to reconstruct the original float from its
+     mantissa and exponent: (f mantissa ldexp:f exponent) = f"
 
 %{  /* NOCONTEXT */
 #ifndef __SCHTEAM__
@@ -2006,6 +2013,9 @@
     ^ super ldexp:exp
 
     "
+     1.0 mantissa ldexp:1.0 exponent  
+     -1.0 mantissa ldexp:-1.0 exponent  
+
      1.0 ldexp:16  -> 65536.0
      1.0 ldexp:100 -> 1.26765060022823E+30
      1 * (2 raisedToInteger:100) -> 1267650600228229401496703205376