UninterpretedBytes.st
changeset 3446 1a8c314b5d7d
parent 3444 09f811ddbb51
child 3447 4009e251544b
--- a/UninterpretedBytes.st	Fri May 15 15:30:28 1998 +0200
+++ b/UninterpretedBytes.st	Fri May 15 17:23:50 1998 +0200
@@ -258,6 +258,29 @@
     "
 !
 
+doubleAt:index MSB:msb
+    "return the 8-bytes starting at index as a Float.
+     The index is a smalltalk index (i.e. 1-based).
+     Notice, that (currently) ST/X Floats are what Doubles are in ST-80.
+     Notice also, that the bytes are expected to be in this machines
+     float representation - if the bytearray originated from another
+     machine, some conversion is usually needed."
+
+    |newFloat|
+
+    msb == UninterpretedBytes isBigEndian ifTrue:[
+        ^ self doubleAt:index.
+    ].
+
+    newFloat := Float basicNew.
+    1 to:8 do:[:destIndex|
+        newFloat basicAt:(9-destIndex) put:(self at:index - 1 + destIndex)
+    ].
+    ^ newFloat.
+
+    "Created: / 15.5.1998 / 17:21:45 / cg"
+!
+
 doubleAt:index put:aFloat
     "store the value of the argument, aFloat into the receiver
      starting at index.
@@ -302,6 +325,30 @@
     ^ aFloat
 !
 
+doubleAt:index put:aFloat MSB:msb
+    "store the value of the argument, aFloat into the receiver
+     starting at index.
+     The index is a smalltalk index (i.e. 1-based).
+     Notice, that (currently) ST/X Floats are what Doubles are in ST-80.
+     Notice also, that the bytes are expected to be in this machines
+     float representation - if the bytearray originated from another
+     machine, some conversion is usually needed."
+
+    |flt|
+
+    msb == UninterpretedBytes isBigEndian ifTrue:[
+        ^ self doubleAt:index.
+    ].
+
+    flt := aFloat asFloat.
+    1 to:8 do:[:srcIndex|
+        self at:index - 1 + srcIndex put:(flt basicAt:(9-srcIndex))
+    ].
+    ^ aFloat
+
+    "Created: / 15.5.1998 / 17:22:27 / cg"
+!
+
 doubleWordAt:index
     "return the 4-bytes starting at index as an (unsigned) Integer.
      The index is a smalltalk index (i.e. 1-based).
@@ -551,6 +598,32 @@
     ^ newFloat.
 !
 
+floatAt:index MSB:msb
+    "return the 4-bytes starting at index as a ShortFloat.
+     The index is a smalltalk index (i.e. 1-based).
+     Notice, that (currently) ST/X Floats are what Doubles are in ST-80;
+     therefore this method reads a 4-byte float from the byteArray and returns
+     a float object which keeps an 8-byte double internally.
+     Notice also, that the bytes are expected to be in this machines
+     float representation and order - if the bytearray originated from another
+     machine, some conversion is usually needed."
+
+    |newFloat|
+
+    msb == UninterpretedBytes isBigEndian ifTrue:[
+        ^ self floatAt:index
+    ].
+
+    newFloat := ShortFloat basicNew.
+    1 to:4 do:[:destIndex|
+        newFloat basicAt:(5-destIndex) put:(self at:index - 1 + destIndex)
+    ].
+    ^ newFloat.
+
+    "Modified: / 15.5.1998 / 17:20:19 / cg"
+    "Created: / 15.5.1998 / 17:20:35 / cg"
+!
+
 floatAt:index put:aFloat
     "store the 4 bytes of value of the argument, aFloat into the receiver
      starting at index.
@@ -596,6 +669,30 @@
     ^ aFloat
 !
 
+floatAt:index put:aFloat MSB:msb
+    "store the 4 bytes of value of the argument, aFloat into the receiver
+     starting at index.
+     The index is a smalltalk index (i.e. 1-based).
+     Notice, that (currently) ST/X Floats are what Doubles are in ST-80.
+     Notice also, that the bytes are expected to be in this machines
+     float representation - if the bytearray originated from another
+     machine, some conversion is usually needed."
+
+    |sflt|
+
+    msb == UninterpretedBytes isBigEndian ifTrue:[
+        ^ self floatAt:index put:aFloat
+    ].
+
+    sflt := aFloat asShortFloat.
+    1 to:4 do:[:srcIndex|
+        self at:index - 1 + srcIndex put:(sflt basicAt:(5-srcIndex))
+    ].
+    ^ aFloat
+
+    "Created: / 15.5.1998 / 17:20:41 / cg"
+!
+
 ieeeDoubleAt:index
     "retrieve the 8 bytes starting at index as a float.
      The index is a smalltalk index (i.e. 1-based).
@@ -1846,6 +1943,6 @@
 !UninterpretedBytes class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/UninterpretedBytes.st,v 1.27 1998-05-14 17:00:09 ca Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/UninterpretedBytes.st,v 1.28 1998-05-15 15:23:50 cg Exp $'
 ! !
 UninterpretedBytes initialize!