Float.st
changeset 44 b262907c93ea
parent 41 a14247b04d03
child 47 93f17a1b452c
--- a/Float.st	Sun Jan 16 04:38:33 1994 +0100
+++ b/Float.st	Sun Jan 16 04:47:41 1994 +0100
@@ -22,7 +22,7 @@
 COPYRIGHT (c) 1988 by Claus Gittinger
               All Rights Reserved
 
-$Header: /cvs/stx/stx/libbasic/Float.st,v 1.8 1994-01-09 21:22:12 claus Exp $
+$Header: /cvs/stx/stx/libbasic/Float.st,v 1.9 1994-01-16 03:41:05 claus Exp $
 
 notice, that Floats are defined as Byte-array to prevent garbage collector
 from going into the value ... otherwise I needed a special case in many places.
@@ -777,20 +777,77 @@
 
 !Float class methodsFor:'binary storage'!
 
+storeBinaryIEEESingle:aFloat on:aStream
+    "store aFloat as an IEEE formatted 4-byte float
+     onto the binary stream, aStream"
+
+    "this implementation is wrong: dous not work on non-IEEE machines"
+    UninterpretedBytes isBigEndian ifTrue:[
+        "swap the bytes"
+        8 to:4 by:-1 do:[:i |
+            aStream nextPut:(aFloat basicAt:i).
+        ].
+        ^ self
+    ].
+    4 to:8 do:[:i |
+        aStream nextPut:(aFloat basicAt:i).
+    ]
+!
+
+storeBinaryIEEEDouble:aFloat on:aStream
+    "store aFloat as an IEEE formatted 8-byte float
+     onto the binary stream, aStream"
+
+    "this implementation is wrong: dous not work on non-IEEE machines"
+    UninterpretedBytes isBigEndian ifTrue:[
+        "swap the bytes"
+        8 to:1 by:-1 do:[:i |
+            aStream nextPut:(aFloat basicAt:i).
+        ].
+        ^ self
+    ].
+    1 to:8 do:[:i |
+        aStream nextPut:(aFloat basicAt:i).
+    ].
+!
+
+readBinaryIEEESingleFrom:aStream into:aFloat
+    "read a float value from the binary stream, aStream,
+     interpreting the next bytes as an IEEE formatted 4-byte float"
+
+    UninterpretedBytes isBigEndian ifTrue:[
+        "swap the bytes"
+        8 to:4 by:-1 do:[:i |
+            aFloat basicAt:i put:(aStream next)
+        ].
+        ^ self
+    ].
+    4 to:8 do:[:i |
+        aFloat basicAt:i put:aStream next
+    ]
+!
+
+readBinaryIEEEDoubleFrom:aStream into:aFloat
+    "read the receivers value from the binary stream, aStream,
+     interpreting the next bytes as an IEEE formatted 8-byte float"
+
+    UninterpretedBytes isBigEndian ifTrue:[
+	"swap the bytes"
+	8 to:1 by:-1 do:[:i |
+	    aFloat basicAt:i put:(aStream next)
+	].
+	^ self
+    ].
+    1 to:8 do:[:i |
+	aFloat basicAt:i put:aStream next
+    ]
+!
+
 binaryDefinitionFrom: stream manager: manager
-    |f bytes|
+    |f|
 
     f := self basicNew.
-    bytes := stream next:8.
-
-    "kludge: assumes IEEE format"
-    UninterpretedBytes isBigEndian ifTrue:[
-        "swap the bytes"
-        bytes reverse.
-    ].
-    1 to:8 do:[:i |
-        f basicAt:i put:(bytes basicAt:i).
-    ].
+    self readBinaryIEEEDoubleFrom:stream into:f.
     ^ f
 ! !
 
@@ -798,16 +855,7 @@
 
 storeBinaryDefinitionOn: stream manager: manager
     manager putIdOf: self class on: stream.
-    UninterpretedBytes isBigEndian ifTrue:[
-        "swap the bytes"
-        8 to:1 by:-1 do:[:i |
-            stream nextPut:(self basicAt:i).
-        ].
-        ^ self
-    ].
-    1 to:8 do:[:i |
-        stream nextPut:(self basicAt:i).
-    ].
+    Float storeBinaryIEEEDouble:self on:stream.
 ! !
 
 !Float methodsFor:'printing and storing'!