Float.st
branchjv
changeset 18045 c0c600e0d3b3
parent 18040 a11a12546f23
parent 15020 d3c13efd316f
child 18060 3708e12e9aa8
--- a/Float.st	Tue Apr 16 14:27:04 2013 +0200
+++ b/Float.st	Thu Apr 18 20:41:50 2013 +0200
@@ -184,19 +184,19 @@
 
 documentation
 "
-    ShortFloats represent rational numbers with limited precision.
+    Floats represent rational numbers with limited precision.
     They use the C-compilers 'double' format, which is usually the 8byte IEE double float format.
 
     Floats give you 64 bit floats.
-    In contrast to ShortFloats and LongFloats.
+    In contrast to ShortFloats (32bit) and LongFloats (>=64bit).
 
     WARNING:
-	The layout of Float instances is known by the runtime system and the compiler;
-	you may not add instance variables here.
-	Also, subclassing is complicated by the fact, that the VM creates floats/shortFloats,
-	and does some float-checks by an identity compare with the Float-class.
-	(i.e. your subclasses instances may not be recognized as float-like objects,
-	 thus mixed mode arithmetic will always coerce them, effectively slowing things down).
+        The layout of Float instances is known by the runtime system and the compiler;
+        you may not add instance variables here.
+        Also, subclassing is complicated by the fact, that the VM creates floats/shortFloats,
+        and does some float-checks by an identity compare with the Float-class.
+        (i.e. your subclasses instances may not be recognized as float-like objects,
+         thus mixed mode arithmetic will always coerce them, effectively slowing things down).
 
     Notice, that Floats are defined as Byte-array to prevent the garbage collector
     from going into the value ... otherwise I needed a special case in many places.
@@ -204,40 +204,39 @@
     Also notice, that ST/X Floats are what Doubles are in ST-80 - this may change
     in one of the next versions (at least on machines, which provide different float
     and double types in their C-compiler).
-    The reason for doung this was to be compatible to both Digitalk and ParcPlace smalltalk
+    The reason for doing this was to be compatible to both Digitalk, Squeak AND ParcPlace smalltalk
     implementations
     (ParcPlace uses a 4-byte Float and an 8-byte Double class, in contrast to
-     Digitalk, which has an 8-byte Float class).
+     Digitalk and Squeak, which have an 8-byte Float class).
     Thus, by providing an 8-byte Float class, code would not loose precicion
     (although some memory is wasted when porting from VW).
-    As Digitalk is dead now, things could (should) now be made to be compatible with VW.
     Notice that ST/X provides an alias called Double, and an extra ShortFloat class, which has 4-byte
     instances.
 
     Mixed mode arithmetic:
-	float op float       -> float
-	float op fix         -> float
-	float op fraction    -> float
-	float op integer     -> float
-	float op shortFloat  -> float
-	float op longFloat   -> longFloat
-	float op complex     -> complex
+        float op float       -> float
+        float op fix         -> float
+        float op fraction    -> float
+        float op integer     -> float
+        float op shortFloat  -> float
+        float op longFloat   -> longFloat
+        float op complex     -> complex
 
     Representation:
-	    64bit double precision IEE floats
-	    53 bit mantissa,
-	    11 bit exponent,
-	    15 decimal digits (approx)
+            64bit double precision IEE floats
+            53 bit mantissa,
+            11 bit exponent,
+            15 decimal digits (approx)
 
     Range and Precision of Storage Formats: see LimitedPrecisionReal >> documentation
 
     [author:]
-	Claus Gittinger
+        Claus Gittinger
 
     [see also:]
-	Number
-	ShortFloat LongFloat Fraction FixedPoint Integer Complex
-	FloatArray DoubleArray
+        Number
+        ShortFloat LongFloat Fraction FixedPoint Integer Complex
+        FloatArray DoubleArray
 "
 !
 
@@ -337,6 +336,21 @@
     "
 !
 
+fromIEEE32Bit: anInteger
+    "creates a double, given the four native float bytes as an integer"
+
+%{  /* NOCONTEXT */
+
+    REGISTER union {
+        unsigned int    i;
+        float           f;
+    } r;
+
+    r.i = __unsignedLongIntVal( anInteger );
+    RETURN( __MKFLOAT((double)(r.f)) );
+%}
+!
+
 fromVAXFloatBytes:b1 b2:b2 b3:b3 b4:b4
     "creates a double, given the four vax float bytes to an ieee double.
      For NaNs and Infinity, nil is returned.
@@ -415,7 +429,7 @@
     |f|
 
     f := self basicNew.
-    self readBinaryIEEEDoubleFrom:aStream into:f.
+    self readBinaryIEEEDoubleFrom:aStream into:f MSB:(UninterpretedBytes isBigEndian).
     ^ f
 
     "not part of libboss, as this is also used by others (TIFFReader)"
@@ -424,6 +438,20 @@
     "Modified: / 23-08-2006 / 16:00:42 / cg"
 !
 
+readBinaryIEEEDoubleFrom:aStream MSB:msbFirst
+    "read a float from the binary stream, aStream,
+     interpreting the next bytes as an IEEE formatted 8-byte float.
+     The bytes are read in the specified byte order"
+
+    |f|
+
+    f := self basicNew.
+    self readBinaryIEEEDoubleFrom:aStream into:f MSB:msbFirst.
+    ^ f
+
+    "not part of libboss, as this is also used by others (TIFFReader)"
+!
+
 readBinaryIEEEDoubleFrom:aStream into:aFloat
     "read the receiver's value from the binary stream, aStream,
      interpreting the next bytes as an IEEE formatted 8-byte float.
@@ -723,6 +751,7 @@
     ^ 2 "must be careful here, whenever ST/X is used on VAX or a 370"
 ! !
 
+
 !Float methodsFor:'arithmetic'!
 
 * aNumber
@@ -1034,7 +1063,7 @@
 !
 
 asFloat
-    "return a float with same value - thats me"
+    "return a float with same value - that's me"
 
     ^ self
 !
@@ -2872,11 +2901,11 @@
 !Float class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.191 2013-03-22 09:44:22 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.195 2013-03-31 20:45:44 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.191 2013-03-22 09:44:22 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.195 2013-03-31 20:45:44 cg Exp $'
 ! !