#REFACTORING by cg
authorClaus Gittinger <cg@exept.de>
Tue, 13 Jun 2017 18:06:51 +0200
changeset 4386 0a320155d78a
parent 4385 3bfafdde1cb5
child 4387 879309cae427
#REFACTORING by cg class: QDouble added: #/ #renorm comment/format in: #asDoubleArray #d0 #d1 #d3 changed: #asFloat #equalFromQDouble: #negative #positive #quotientFromQDouble:
QDouble.st
--- a/QDouble.st	Tue Jun 13 17:56:31 2017 +0200
+++ b/QDouble.st	Tue Jun 13 18:06:51 2017 +0200
@@ -917,34 +917,40 @@
     "
 
     "Created: / 12-06-2017 / 23:41:39 / cg"
+!
+
+/ aNumber
+    "return the quotient of the receiver and the argument, aNumber"
+
+    ^ aNumber quotientFromQDouble:self
+
+    "
+     ((QDouble fromFloat:1e20) / (QDouble fromFloat:2.0)) asDoubleArray
+    "
+
+    "Created: / 13-06-2017 / 17:59:09 / cg"
 ! !
 
 !QDouble methodsFor:'coercing & converting'!
 
 asDoubleArray
-    |a|
-
-    a := DoubleArray new:4.
-%{
-    __DoubleArrayInstPtr(a)->d_element[0] = __QuadDoubleInstPtr(self)->d_quadDoubleValue[0]; 
-    __DoubleArrayInstPtr(a)->d_element[1] = __QuadDoubleInstPtr(self)->d_quadDoubleValue[1]; 
-    __DoubleArrayInstPtr(a)->d_element[2] = __QuadDoubleInstPtr(self)->d_quadDoubleValue[2]; 
-    __DoubleArrayInstPtr(a)->d_element[3] = __QuadDoubleInstPtr(self)->d_quadDoubleValue[3]; 
-%}.
-    ^ a
+    ^ DoubleArray 
+            with:self d0 
+            with:self d1 
+            with:self d2 
+            with:self d3.
 
     "
-     (QuadDouble fromFloat:1.0) asDoubleArray
-     (QuadDouble fromFloat:2.0) asDoubleArray
+     (QDouble fromFloat:1.0) asDoubleArray
+     (QDouble fromFloat:2.0) asDoubleArray
     "
 
     "Created: / 12-06-2017 / 18:19:19 / cg"
+    "Modified (comment): / 13-06-2017 / 17:58:09 / cg"
 !
 
 asFloat
-%{
-    RETURN ( __MKFLOAT(__QuadDoubleInstPtr(self)->d_quadDoubleValue[0]) ); 
-%}
+    ^ self d0
 
     "
      (QDouble fromFloat:1.0) asFloat
@@ -952,6 +958,7 @@
     "
 
     "Created: / 12-06-2017 / 18:15:27 / cg"
+    "Modified: / 13-06-2017 / 17:56:50 / cg"
 !
 
 coerce:aNumber
@@ -972,9 +979,7 @@
 !
 
 negative
-%{
-    RETURN ( __QuadDoubleInstPtr(self)->d_quadDoubleValue[0] < 0 ? true : false ); 
-%}
+    ^ self d0 negative
 
     "
      (QDouble fromFloat:0.0) negative
@@ -983,12 +988,11 @@
     "
 
     "Created: / 13-06-2017 / 01:57:39 / cg"
+    "Modified: / 13-06-2017 / 17:58:26 / cg"
 !
 
 positive
-%{
-    RETURN ( __QuadDoubleInstPtr(self)->d_quadDoubleValue[0] >= 0 ? true : false ); 
-%}
+    ^ self d0 positive
 
     "
      (QDouble fromFloat:1.0) positive
@@ -996,6 +1000,7 @@
     "
 
     "Created: / 13-06-2017 / 01:56:53 / cg"
+    "Modified: / 13-06-2017 / 17:58:41 / cg"
 ! !
 
 !QDouble methodsFor:'comparing'!
@@ -1068,7 +1073,10 @@
                 && a[3] == b[3]) ? true : false);
     }
 %}.
-    ^ super equalFromQDouble:aQDouble
+    ^ (aQDouble d0 = self d0)
+    and:[ (aQDouble d1 = self d1)
+    and:[ (aQDouble d2 = self d2)
+    and:[ (aQDouble d3 = self d3) ]]]
     
     "
      (QDouble fromFloat:1.0) = (QDouble fromFloat:1.0)
@@ -1077,7 +1085,7 @@
    "
 
     "Created: / 13-06-2017 / 03:01:19 / cg"
-    "Modified (comment): / 13-06-2017 / 08:43:45 / cg"
+    "Modified: / 13-06-2017 / 18:01:52 / cg"
 !
 
 lessFromQDouble:aQDouble
@@ -1215,6 +1223,8 @@
 !
 
 quotientFromQDouble:aQDouble
+    "sloppy"
+    
     |q0 q1 q2 q3 r|
 
     q0 := self d0 / aQDouble d0.
@@ -1227,20 +1237,10 @@
     r := r - (aQDouble * q2).
 
     q3 := r d0 / aQDouble d0.
-%{
-    {
-        double _q0 = __floatVal(q0);
-        double _q1 = __floatVal(q1);
-        double _q2 = __floatVal(q2);
-        double _q3 = __floatVal(q3);;
-        OBJ newQD;
-        
-        m_renorm4(_q0, _q1, _q2, _q3);
-        __qNew_qdReal(newQD, _q0, _q1, _q2, _q3);
-        RETURN( newQD );
-    }
-%}.
-    ^ super quotientFromQDouble:aQDouble.
+
+    r := self class d0:q0 d1:q1 d2:q2 d3:q3.
+    r renorm.
+    ^ r
 
     "
      2.0 / (QDouble fromFloat:2.0)
@@ -1634,19 +1634,23 @@
 !QDouble methodsFor:'private accessing'!
 
 d0
+    "the most significant (and highest valued) 53 bits of precision"
 %{
     RETURN ( __MKFLOAT(__QuadDoubleInstPtr(self)->d_quadDoubleValue[0]) ); 
 %}
 
     "Created: / 12-06-2017 / 20:15:12 / cg"
+    "Modified (comment): / 13-06-2017 / 17:59:47 / cg"
 !
 
 d1
+    "the next most significant (and next highest valued) 53 bits of precision"
 %{
     RETURN ( __MKFLOAT(__QuadDoubleInstPtr(self)->d_quadDoubleValue[1]) ); 
 %}
 
     "Created: / 12-06-2017 / 20:15:12 / cg"
+    "Modified (comment): / 13-06-2017 / 18:00:00 / cg"
 !
 
 d2
@@ -1658,11 +1662,39 @@
 !
 
 d3
+    "the least significant (and smallest valued) 53 bits of precision"
 %{
     RETURN ( __MKFLOAT(__QuadDoubleInstPtr(self)->d_quadDoubleValue[3]) ); 
 %}
 
     "Created: / 12-06-2017 / 20:15:32 / cg"
+    "Modified (comment): / 13-06-2017 / 18:00:18 / cg"
+!
+
+renorm
+%{
+    double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue; 
+    double c0, c1, c2, c3;
+    OBJ newQD;
+
+    c0 = a[0];
+    c1 = a[1];
+    c2 = a[2];
+    c3 = a[3];
+    m_renorm4(c0, c1, c2, c3);
+    a[0] = c0;
+    a[1] = c1;
+    a[2] = c2;
+    a[3] = c3;
+    RETURN( self );
+%}.
+    ^ self error.
+
+    "
+     (QDouble fromFloat:1.0) renorm
+    "
+
+    "Created: / 13-06-2017 / 18:05:33 / cg"
 ! !
 
 !QDouble class methodsFor:'documentation'!