--- a/ShortFloat.st Mon Mar 18 22:12:08 2013 +0000
+++ b/ShortFloat.st Fri Mar 22 09:18:54 2013 +0000
@@ -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|
@@ -362,7 +363,18 @@
readBinaryIEEESingleFrom:aStream into:aFloat
"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)"
+
+ ^ self readBinaryIEEESingleFrom:aStream into:aFloat MSB:(UninterpretedBytes isBigEndian)
+
+ "Modified: / 23-08-2006 / 16:01:52 / cg"
+!
+
+readBinaryIEEESingleFrom:aStream into:aFloat MSB:msb
+ "read a float value from the binary stream, aStream,
+ interpreting the next bytes as an IEEE formatted 4-byte float.
+ If msb is true, the stream bytes are most-significant-first."
aFloat class == self ifFalse:[self error:'no a ShortFloat'].
@@ -373,15 +385,15 @@
"
self isIEEEFormat ifFalse:[self error:'unsupported operation'].
- UninterpretedBytes isBigEndian ifFalse:[
- "swap the bytes"
- 4 to:1 by:-1 do:[:i |
- aFloat basicAt:i put:(aStream next)
- ].
- ^ self
+ (UninterpretedBytes isBigEndian == msb) ifFalse:[
+ "swap the bytes"
+ 4 to:1 by:-1 do:[:i |
+ aFloat basicAt:i put:(aStream next)
+ ].
+ ^ self
].
1 to:4 do:[:i |
- aFloat basicAt:i put:aStream next
+ aFloat basicAt:i put:aStream next
]
"not part of libboss, as this is also used by others (TIFFReader)"
@@ -391,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|
@@ -404,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)"
@@ -450,7 +471,6 @@
"Modified: 23.4.1996 / 09:26:45 / cg"
! !
-
!ShortFloat class methodsFor:'queries'!
exponentCharacter
@@ -475,6 +495,12 @@
Machines with non-IEEE format are VAXed and IBM370-type systems
(among others). Today, most systems use IEEE format floats."
+%{
+#ifdef __s390__
+ RETURN(false);
+#endif
+%}.
+
^ true "/ this may be a lie
!
@@ -1843,10 +1869,10 @@
!ShortFloat class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/ShortFloat.st,v 1.118 2013-02-04 17:17:43 stefan 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.118 2013-02-04 17:17:43 stefan Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/ShortFloat.st,v 1.121 2013-03-20 15:42:38 cg Exp $'
! !