allow saving in msb
authorClaus Gittinger <cg@exept.de>
Wed, 20 Mar 2013 16:42:38 +0100
changeset 14924 7115c6830ed8
parent 14923 d17a1105f17c
child 14925 046356fde326
allow saving in msb
ShortFloat.st
--- a/ShortFloat.st	Wed Mar 20 16:01:25 2013 +0100
+++ b/ShortFloat.st	Wed Mar 20 16:42:38 2013 +0100
@@ -346,7 +346,8 @@
 
 readBinaryIEEESingleFrom:aStream
     "read a float value from the binary stream, aStream,
-     interpreting the next bytes as an IEEE formatted 4-byte float"
+     interpreting the next bytes as an IEEE formatted 4-byte float.
+     The bytes are read in the native byte order (i.e.lsb on intel)"
 
     |f|
 
@@ -363,7 +364,7 @@
 readBinaryIEEESingleFrom:aStream into:aFloat
     "read a float value from the binary stream, aStream,
      interpreting the next bytes as an IEEE formatted 4-byte float.
-     The bytes are read in the nativ byte order (i.e.lsb on intel)"
+     The bytes are read in the native byte order (i.e.lsb on intel)"
 
     ^ self readBinaryIEEESingleFrom:aStream into:aFloat MSB:(UninterpretedBytes isBigEndian)
 
@@ -402,7 +403,16 @@
 
 storeBinaryIEEESingle:aFloat on:aStream
     "store aFloat as an IEEE formatted 4-byte float
-     onto the binary stream, aStream"
+     onto the binary stream, aStream.
+     The bytes are written in the native byte order (i.e.lsb on intel)"
+
+    self storeBinaryIEEESingle:aFloat on:aStream MSB:(UninterpretedBytes isBigEndian).
+!
+
+storeBinaryIEEESingle:aFloat on:aStream MSB:msb
+    "store aFloat as an IEEE formatted 4-byte float
+     onto the binary stream, aStream.
+     If msb is true, the stream bytes are written most-significant-first."
 
     |float|
 
@@ -415,15 +425,15 @@
     "
     self isIEEEFormat ifFalse:[self error:'unsupported operation'].
 
-    UninterpretedBytes isBigEndian ifFalse:[
-	"swap the bytes"
-	4 to:1 by:-1 do:[:i |
-	    aStream nextPut:(float basicAt:i).
-	].
-	^ self
+    (UninterpretedBytes isBigEndian == msb) ifFalse:[
+        "swap the bytes"
+        4 to:1 by:-1 do:[:i |
+            aStream nextPut:(float basicAt:i).
+        ].
+        ^ self
     ].
     1 to:4 do:[:i |
-	aStream nextPut:(float basicAt:i).
+        aStream nextPut:(float basicAt:i).
     ]
 
     "not part of libboss, as this is also used by others (TIFFReader)"
@@ -1859,10 +1869,10 @@
 !ShortFloat class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/ShortFloat.st,v 1.120 2013-03-20 15:01:14 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ShortFloat.st,v 1.121 2013-03-20 15:42:38 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/ShortFloat.st,v 1.120 2013-03-20 15:01:14 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ShortFloat.st,v 1.121 2013-03-20 15:42:38 cg Exp $'
 ! !