Float.st
changeset 4655 b9405ca0bb4e
parent 4615 e480d1e6090f
child 4682 4158042a9c8c
--- a/Float.st	Wed Sep 01 21:52:42 1999 +0200
+++ b/Float.st	Wed Sep 01 21:55:23 1999 +0200
@@ -524,6 +524,17 @@
 
 !Float class methodsFor:'queries'!
 
+hasSharedInstances
+    "return true if this class has shared instances, that is, instances
+     with the same value are identical.
+     Although not really shared, floats should be treated
+     so, to be independent of the implementation of the arithmetic methods."
+
+    ^ true
+
+
+!
+
 isBuiltInClass
     "return true if this class is known by the run-time-system.
      Here, true is returned for myself, false for subclasses."
@@ -628,31 +639,31 @@
     double result, val;
 
     if (__isSmallInteger(aNumber)) {
-        if (aNumber != __MKSMALLINT(0)) {
-            result = __floatVal(self) / ( (double)__intVal(aNumber)) ;
+	if (aNumber != __MKSMALLINT(0)) {
+	    result = __floatVal(self) / ( (double)__intVal(aNumber)) ;
 retResult:
-            __qMKFLOAT(newFloat, result);
-            RETURN ( newFloat );
-        }
+	    __qMKFLOAT(newFloat, result);
+	    RETURN ( newFloat );
+	}
     } else if (__isFloatLike(aNumber)) {
-        val = __floatVal(aNumber);
-        if (val != 0.0) {
-            result = __floatVal(self) / val;
-            goto retResult;
-        }
+	val = __floatVal(aNumber);
+	if (val != 0.0) {
+	    result = __floatVal(self) / val;
+	    goto retResult;
+	}
     } else if (__isShortFloat(aNumber)) {
-        val = (double)(__shortFloatVal(aNumber));
-        if (val != 0.0) {
-            result = __floatVal(self) / val;
-            goto retResult;
-        }
+	val = (double)(__shortFloatVal(aNumber));
+	if (val != 0.0) {
+	    result = __floatVal(self) / val;
+	    goto retResult;
+	}
     }
 %}.
     ((aNumber == 0) or:[aNumber = 0.0]) ifTrue:[
-        "
-         No, you shalt not divide by zero
-        "
-        ^ DivisionByZeroSignal raiseRequest.
+	"
+	 No, you shalt not divide by zero
+	"
+	^ DivisionByZeroSignal raiseRequest.
     ].
     ^ aNumber quotientFromFloat:self
 !
@@ -775,11 +786,11 @@
     "Extract the bits of an IEEE double float "
     UninterpretedBytes isBigEndian ifTrue:[
 "/        shifty := ((self basicAt: 1) bitShift: 32) + (self basicAt: 2).
-        shifty := LargeInteger basicNew numberOfDigits:8.
-        1 to:8 do:[:i | shifty digitAt:(9-i) put:(self basicAt:i)].
+	shifty := LargeInteger basicNew numberOfDigits:8.
+	1 to:8 do:[:i | shifty digitAt:(9-i) put:(self basicAt:i)].
     ] ifFalse:[
-        shifty := LargeInteger basicNew numberOfDigits:8.
-        1 to:8 do:[:i | shifty digitAt:i put:(self basicAt:i)].
+	shifty := LargeInteger basicNew numberOfDigits:8.
+	1 to:8 do:[:i | shifty digitAt:i put:(self basicAt:i)].
     ].
 
     " Extract the sign and the biased exponent "
@@ -800,19 +811,19 @@
       the number of trailing zero bits in the fraction to minimize
       the (huge) time otherwise spent in #gcd:. "
     exp negative ifTrue: [
-        result := sign * fraction bitShift: exp negated 
+	result := sign * fraction bitShift: exp negated 
     ] ifFalse:[
-        zeroBitsCount := fraction lowBit - 1.
-        exp := exp - zeroBitsCount.
-        exp <= 0 ifTrue: [
-            zeroBitsCount := zeroBitsCount + exp.
-            "exp := 0."   " Not needed; exp not refernced again "
-            result := sign * fraction bitShift:zeroBitsCount negated 
-        ] ifFalse: [
-            result := Fraction
-                    numerator: (sign * fraction bitShift: zeroBitsCount negated)
-                    denominator: (1 bitShift:exp) 
-        ] 
+	zeroBitsCount := fraction lowBit - 1.
+	exp := exp - zeroBitsCount.
+	exp <= 0 ifTrue: [
+	    zeroBitsCount := zeroBitsCount + exp.
+	    "exp := 0."   " Not needed; exp not refernced again "
+	    result := sign * fraction bitShift:zeroBitsCount negated 
+	] ifFalse: [
+	    result := Fraction
+		    numerator: (sign * fraction bitShift: zeroBitsCount negated)
+		    denominator: (1 bitShift:exp) 
+	] 
     ].
 
     "Low cost validation omitted after extensive testing"
@@ -941,10 +952,10 @@
     |i|
 
     (self >= SmallInteger minVal and:[self <= SmallInteger maxVal]) ifTrue:[
-        i := self asInteger.
-        self = i ifTrue:[
-            ^ i hash
-        ].
+	i := self asInteger.
+	self = i ifTrue:[
+	    ^ i hash
+	].
     ].
 
     "
@@ -1397,12 +1408,12 @@
      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."
+	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 */
 
@@ -1415,15 +1426,15 @@
      * and SmallInteger
      */
     if (__isSmallInteger(index)) {
-        indx = __intVal(index) - 1;
-        if (((unsigned)(indx)) < sizeof(double)) {
-            cp = (unsigned char *)(& (__FloatInstPtr(self)->f_floatvalue));
-            RETURN ( __MKSMALLINT(cp[indx] & 0xFF) );
-        }
+	indx = __intVal(index) - 1;
+	if (((unsigned)(indx)) < sizeof(double)) {
+	    cp = (unsigned char *)(& (__FloatInstPtr(self)->f_floatvalue));
+	    RETURN ( __MKSMALLINT(cp[indx] & 0xFF) );
+	}
     }
 %}.
     index isInteger ifFalse:[
-        ^ self indexNotInteger
+	^ self indexNotInteger
     ].
     ^ self subscriptBoundsError:index
 !
@@ -1434,12 +1445,12 @@
      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."
+	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;
@@ -1451,31 +1462,31 @@
      * 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(double)) {
-                cp = (unsigned char *)(& (__FloatInstPtr(self)->f_floatvalue));
-                cp[indx] = val;
-                RETURN ( value );
-            }
-        }
+	val = __intVal(value);
+	if ((val & ~0xFF) == 0 /* i.e. (val >= 0) && (val <= 255) */) {
+	    indx = __intVal(index) - 1;
+	    if (((unsigned)(indx)) < sizeof(double)) {
+		cp = (unsigned char *)(& (__FloatInstPtr(self)->f_floatvalue));
+		cp[indx] = val;
+		RETURN ( value );
+	    }
+	}
     }
 %}.
     index isInteger ifFalse:[
-        ^ self indexNotInteger
+	^ self indexNotInteger
     ].
     value isInteger ifFalse:[
-        "
-         the object to store should be an integer number
-        "
-        ^ self elementNotInteger
+	"
+	 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
+	"
+	 the object to store must be a bytes value
+	"
+	^ self elementBoundsError
     ].
     ^ self subscriptBoundsError:index
 !
@@ -1484,12 +1495,12 @@
     "return the size in bytes of the float.
 
      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."
+	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 */
 
@@ -1625,6 +1636,15 @@
     "
 !
 
+isLiteral
+    "return true, if the receiver can be used as a literal constant in ST syntax
+     (i.e. can be used in constant arrays)"
+
+    ^ true
+
+
+!
+
 isNaN
     "return true, if the receiver is an invalid float (NaN - not a number).
      These are not created by ST/X float operations (they raise an exception);
@@ -1731,6 +1751,16 @@
 %}
 ! !
 
+!Float methodsFor:'tracing'!
+
+traceInto:aRequestor level:level
+    "double dispatch into tracer, passing my type implicitely in the selector"
+
+    ^ aRequestor traceFloat:self level:level
+
+
+! !
+
 !Float methodsFor:'truncation and rounding'!
 
 ceiling
@@ -1996,6 +2026,6 @@
 !Float class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.101 1999-08-19 01:19:32 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.102 1999-09-01 19:54:53 cg Exp $'
 ! !
 Float initialize!