class: Float
added: #readBinaryIEEEDoubleFrom:into:MSB:
changed:
#isIEEEFormat
#readBinaryIEEEDoubleFrom:into:
--- a/Float.st Wed Mar 20 16:01:14 2013 +0100
+++ b/Float.st Wed Mar 20 16:01:25 2013 +0100
@@ -419,25 +419,34 @@
!
readBinaryIEEEDoubleFrom:aStream into:aFloat
- "read the receivers value from the binary stream, aStream,
- interpreting the next bytes as an IEEE formatted 8-byte float"
+ "read the receiver's value from the binary stream, aStream,
+ interpreting the next bytes as an IEEE formatted 8-byte float.
+ The bytes are read in the nativ byte order (i.e.lsb on intel)"
+
+ ^ self readBinaryIEEEDoubleFrom:aStream into:aFloat MSB:(UninterpretedBytes isBigEndian)
+!
+
+readBinaryIEEEDoubleFrom:aStream into:aFloat MSB:msb
+ "read the receiver's value from the binary stream, aStream,
+ interpreting the next bytes as an IEEE formatted 8-byte float.
+ If msb is true, the stream bytes are most-significant-first."
"
this implementation is wrong: does not work on non-IEEE machines
(to date all machines where ST/X is running on use
- IEEE float format. Need more here, when porting ST/X to 370's)
+ IEEE float format. Will need more here, when porting ST/X to 370's)
"
self isIEEEFormat ifFalse:[self error:'unsupported operation'].
- UninterpretedBytes isBigEndian ifFalse:[
- "swap the bytes"
- 8 to:1 by:-1 do:[:i |
- aFloat basicAt:i put:(aStream next)
- ].
- ^ self
+ (UninterpretedBytes isBigEndian == msb) ifFalse:[
+ "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
+ aFloat basicAt:i put:aStream next
]
"not part of libboss, as this is also used by others (TIFFReader)"
@@ -622,7 +631,6 @@
"
! !
-
!Float class methodsFor:'queries'!
exponentCharacter
@@ -657,6 +665,11 @@
machine).
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
!
@@ -695,7 +708,6 @@
^ 2 "must be careful here, whenever ST/X is used on VAX or a 370"
! !
-
!Float methodsFor:'arithmetic'!
* aNumber
@@ -865,6 +877,40 @@
^ aNumber quotientFromFloat:self
!
+abs
+ "return the absolute value of the receiver
+ reimplemented here for speed"
+
+%{ /* NOCONTEXT */
+
+ OBJ newFloat;
+ double val =__floatVal(self);
+
+ if (val < 0.0) {
+ __qMKFLOAT(newFloat, -val);
+ RETURN ( newFloat );
+ }
+ RETURN (self);
+%}.
+
+ "
+ 3.0 abs
+ -3.0 abs
+ "
+!
+
+negated
+ "return myself negated"
+
+%{ /* NOCONTEXT */
+ OBJ newFloat;
+ double rslt = - __floatVal(self);
+
+ __qMKFLOAT(newFloat, rslt);
+ RETURN ( newFloat );
+%}.
+!
+
rem: aNumber
"return the floating point remainder of the receiver and the argument, aNumber"
@@ -924,40 +970,6 @@
^ aNumber remainderFromFloat:self
!
-abs
- "return the absolute value of the receiver
- reimplemented here for speed"
-
-%{ /* NOCONTEXT */
-
- OBJ newFloat;
- double val =__floatVal(self);
-
- if (val < 0.0) {
- __qMKFLOAT(newFloat, -val);
- RETURN ( newFloat );
- }
- RETURN (self);
-%}.
-
- "
- 3.0 abs
- -3.0 abs
- "
-!
-
-negated
- "return myself negated"
-
-%{ /* NOCONTEXT */
- OBJ newFloat;
- double rslt = - __floatVal(self);
-
- __qMKFLOAT(newFloat, rslt);
- RETURN ( newFloat );
-%}.
-!
-
uncheckedDivide:aNumber
"return the quotient of the receiver and the argument, aNumber.
Do not check for divide by zero (return NaN or Infinity).
@@ -1553,7 +1565,6 @@
"Modified: / 16.11.2001 / 14:14:43 / cg"
! !
-
!Float methodsFor:'printing & storing'!
printString
@@ -1950,7 +1961,6 @@
"
! !
-
!Float methodsFor:'testing'!
isFinite
@@ -2847,11 +2857,11 @@
!Float class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.187 2013-02-05 15:29:32 stefan Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.188 2013-03-20 15:01:25 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.187 2013-02-05 15:29:32 stefan Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.188 2013-03-20 15:01:25 cg Exp $'
! !