--- a/ShortFloat.st Sun Dec 27 19:45:23 2009 +0000
+++ b/ShortFloat.st Sun Dec 27 20:16:54 2009 +0000
@@ -354,14 +354,14 @@
self isIEEEFormat ifFalse:[self error:'unsupported operation'].
UninterpretedBytes isBigEndian ifFalse:[
- "swap the bytes"
- 8 to:4 by:-1 do:[:i |
- aFloat basicAt:i put:(aStream next)
- ].
- ^ self
+ "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)"
@@ -385,14 +385,14 @@
self isIEEEFormat ifFalse:[self error:'unsupported operation'].
UninterpretedBytes isBigEndian ifFalse:[
- "swap the bytes"
- 8 to:4 by:-1 do:[:i |
- aStream nextPut:(float basicAt:i).
- ].
- ^ self
+ "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)"
@@ -1129,6 +1129,91 @@
"
! !
+!ShortFloat methodsFor:'private accessing'!
+
+basicAt:index
+ "return an internal byte of the float.
+ The value returned here depends on byte order, float representation etc.
+ Therefore, this method should be used strictly private.
+
+ Notice:
+ the need to redefine this method here is due to the
+ inability of many machines to store floats in non-double aligned memory.
+ Therefore, on some machines, the first 4 bytes of a float are left unused,
+ and the actual float is stored at index 5 .. 12.
+ To hide this at one place, this method knows about that, and returns
+ values as if this filler wasnt present."
+
+%{ /* NOCONTEXT */
+
+ register int indx;
+ unsigned char *cp;
+
+ /*
+ * notice the missing test for self being a nonNilObject -
+ * this can be done since basicAt: is defined both in UndefinedObject
+ * and SmallInteger
+ */
+ if (__isSmallInteger(index)) {
+ indx = __intVal(index) - 1;
+ if (((unsigned)(indx)) < sizeof(float)) {
+ cp = (unsigned char *)(& (__ShortFloatInstPtr(self)->f_floatvalue));
+ RETURN ( __mkSmallInteger(cp[indx] & 0xFF) );
+ }
+ }
+%}.
+ ^ self indexNotIntegerOrOutOfBounds:index
+!
+
+basicAt:index put:value
+ "set an internal byte of the float.
+ The value to be stored here depends on byte order, float representation etc.
+ Therefore, this method should be used strictly private.
+
+ Notice:
+ the need to redefine this method here is due to the
+ inability of many machines to store floats in non-double aligned memory.
+ Therefore, on some machines, the first 4 bytes of a float are left unused,
+ and the actual float is stored at index 5 .. 12.
+ To hide this at one place, this method knows about that, and returns
+ values as if this filler wasnt present."
+
+%{ /* NOCONTEXT */
+ register int indx, val;
+ unsigned char *cp;
+
+ /*
+ * notice the missing test for self being a nonNilObject -
+ * this can be done since basicAt: is defined both in UndefinedObject
+ * and SmallInteger
+ */
+ if (__bothSmallInteger(index, value)) {
+ val = __intVal(value);
+ if ((val & ~0xFF) == 0 /* i.e. (val >= 0) && (val <= 255) */) {
+ indx = __intVal(index) - 1;
+ if (((unsigned)(indx)) < sizeof(float)) {
+ cp = (unsigned char *)(& (__ShortFloatInstPtr(self)->f_floatvalue));
+ cp[indx] = val;
+ RETURN ( value );
+ }
+ }
+ }
+%}.
+ value isInteger ifFalse:[
+ "
+ the object to store should be an integer number
+ "
+ ^ self elementNotInteger
+ ].
+ (value between:0 and:255) ifFalse:[
+ "
+ the object to store must be a bytes value
+ "
+ ^ self elementBoundsError:value
+ ].
+ ^ self indexNotIntegerOrOutOfBounds:index
+! !
+
!ShortFloat methodsFor:'special access'!
exponent
@@ -1636,11 +1721,12 @@
!ShortFloat class methodsFor:'documentation'!
version
- ^ '$Id: ShortFloat.st 10480 2009-12-02 21:30:55Z vranyj1 $'
+ ^ '$Id: ShortFloat.st 10489 2009-12-27 20:16:54Z vranyj1 $'
!
version_CVS
- ^ '§Header: /cvs/stx/stx/libbasic/ShortFloat.st,v 1.101 2009/11/05 16:26:31 stefan Exp §'
+ ^ '§Header: /cvs/stx/stx/libbasic/ShortFloat.st,v 1.103 2009/12/18 14:41:46 cg Exp §'
! !
+