docu & limited shortFloat support
authorClaus Gittinger <cg@exept.de>
Wed, 17 Apr 1996 12:31:49 +0200
changeset 1198 284eeba6b719
parent 1197 2b37cf664b81
child 1199 c37d927155e2
docu & limited shortFloat support
Float.st
--- a/Float.st	Wed Apr 17 12:30:43 1996 +0200
+++ b/Float.st	Wed Apr 17 12:31:49 1996 +0200
@@ -11,10 +11,10 @@
 "
 
 LimitedPrecisionReal variableByteSubclass:#Float
-	 instanceVariableNames:''
-	 classVariableNames:'LastErrorNumber'
-	 poolDictionaries:''
-	 category:'Magnitude-Numbers'
+	instanceVariableNames:''
+	classVariableNames:'LastErrorNumber'
+	poolDictionaries:''
+	category:'Magnitude-Numbers'
 !
 
 !Float primitiveDefinitions!
@@ -64,16 +64,14 @@
     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, and does 
-    its float-checks by an identity compare with the Float-class. (i.e. your subclasses 
-    instances will not be recognized as float-like objects, thus mixed mode arithmetic 
-    will always coerce them, effectively slowing things down).
 
-    This may be changed, to use a flag bit in the class.
+    Also, subclassing is complicated by the fact, that the VM creates floats as results
+    of arithmetic operations (even if the operands are subclass-instances).
+    (It does the float-check by probing a bit in the classes flag instVar).
 
     Class Variables:
 
-	LastErrorNumber <Integer>       value of errno (after a trig- or other math err)
+        LastErrorNumber <Integer>       value of errno (after a trig- or other math err)
 "
 ! !
 
@@ -95,12 +93,27 @@
 
 !Float class methodsFor:'binary storage'!
 
-binaryDefinitionFrom: stream manager: manager
+binaryDefinitionFrom:aStream manager: manager
     |f|
 
     f := self basicNew.
-    self readBinaryIEEEDoubleFrom:stream into:f.
+    self readBinaryIEEEDoubleFrom:aStream into:f.
     ^ f
+
+    "Modified: 16.4.1996 / 21:23:38 / cg"
+!
+
+readBinaryIEEEDoubleFrom:aStream
+    "read a float from the binary stream, aStream,
+     interpreting the next bytes as an IEEE formatted 8-byte float"
+
+    |f|
+
+    f := self basicNew.
+    self readBinaryIEEEDoubleFrom:aStream into:f.
+    ^ f
+
+    "Created: 16.4.1996 / 20:59:59 / cg"
 !
 
 readBinaryIEEEDoubleFrom:aStream into:aFloat
@@ -124,6 +137,19 @@
     ]
 !
 
+readBinaryIEEESingleFrom:aStream
+    "read a float value from the binary stream, aStream,
+     interpreting the next bytes as an IEEE formatted 4-byte float"
+
+    |f|
+
+    f := self basicNew.
+    self readBinaryIEEESingleFrom:aStream into:f.
+    ^ f
+
+    "Created: 16.4.1996 / 21:00:35 / cg"
+!
+
 readBinaryIEEESingleFrom:aStream into:aFloat
     "read a float value from the binary stream, aStream,
      interpreting the next bytes as an IEEE formatted 4-byte float"
@@ -363,22 +389,33 @@
 asInteger
     "return an integer with same value - might truncate"
 
-    |l v sign|
-
 %{  /* NOCONTEXT */
 
     if ((__floatVal(self) >= (double)_MIN_INT)
      && (__floatVal(self) <= (double)_MAX_INT)) {
-	RETURN ( __MKSMALLINT( (INT)__floatVal(self)) );
+        RETURN ( __MKSMALLINT( (INT)__floatVal(self)) );
     }
-%}
-.
+%}.
     ^ super asInteger
 
     "12345.0 asInteger"
     "1e15 asInteger"
 !
 
+asShortFloat
+    "return a shortFloat with same value as receiver"
+
+%{  /* NOCONTEXT */
+
+    OBJ dummy = @global(ShortFloat);
+    OBJ newFloat;
+    float fVal = (float)__floatVal(self);
+
+    __qMKSFLOAT(newFloat, fVal, SENDER);
+    RETURN ( newFloat );
+%}
+!
+
 coerce:aNumber
     "return aNumber converted into receivers type"
 
@@ -1026,5 +1063,5 @@
 !Float class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.34 1996-04-02 22:01:51 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.35 1996-04-17 10:31:49 cg Exp $'
 ! !