QDouble.st
changeset 4386 0a320155d78a
parent 4385 3bfafdde1cb5
child 4387 879309cae427
equal deleted inserted replaced
4385:3bfafdde1cb5 4386:0a320155d78a
   915      ((QDouble fromFloat:1e-20) - (QDouble fromFloat:1.0)) asDoubleArray
   915      ((QDouble fromFloat:1e-20) - (QDouble fromFloat:1.0)) asDoubleArray
   916      ((QDouble fromFloat:2.0) - (QDouble fromFloat:1.0)) asDoubleArray
   916      ((QDouble fromFloat:2.0) - (QDouble fromFloat:1.0)) asDoubleArray
   917     "
   917     "
   918 
   918 
   919     "Created: / 12-06-2017 / 23:41:39 / cg"
   919     "Created: / 12-06-2017 / 23:41:39 / cg"
       
   920 !
       
   921 
       
   922 / aNumber
       
   923     "return the quotient of the receiver and the argument, aNumber"
       
   924 
       
   925     ^ aNumber quotientFromQDouble:self
       
   926 
       
   927     "
       
   928      ((QDouble fromFloat:1e20) / (QDouble fromFloat:2.0)) asDoubleArray
       
   929     "
       
   930 
       
   931     "Created: / 13-06-2017 / 17:59:09 / cg"
   920 ! !
   932 ! !
   921 
   933 
   922 !QDouble methodsFor:'coercing & converting'!
   934 !QDouble methodsFor:'coercing & converting'!
   923 
   935 
   924 asDoubleArray
   936 asDoubleArray
   925     |a|
   937     ^ DoubleArray 
   926 
   938             with:self d0 
   927     a := DoubleArray new:4.
   939             with:self d1 
   928 %{
   940             with:self d2 
   929     __DoubleArrayInstPtr(a)->d_element[0] = __QuadDoubleInstPtr(self)->d_quadDoubleValue[0]; 
   941             with:self d3.
   930     __DoubleArrayInstPtr(a)->d_element[1] = __QuadDoubleInstPtr(self)->d_quadDoubleValue[1]; 
   942 
   931     __DoubleArrayInstPtr(a)->d_element[2] = __QuadDoubleInstPtr(self)->d_quadDoubleValue[2]; 
   943     "
   932     __DoubleArrayInstPtr(a)->d_element[3] = __QuadDoubleInstPtr(self)->d_quadDoubleValue[3]; 
   944      (QDouble fromFloat:1.0) asDoubleArray
   933 %}.
   945      (QDouble fromFloat:2.0) asDoubleArray
   934     ^ a
       
   935 
       
   936     "
       
   937      (QuadDouble fromFloat:1.0) asDoubleArray
       
   938      (QuadDouble fromFloat:2.0) asDoubleArray
       
   939     "
   946     "
   940 
   947 
   941     "Created: / 12-06-2017 / 18:19:19 / cg"
   948     "Created: / 12-06-2017 / 18:19:19 / cg"
       
   949     "Modified (comment): / 13-06-2017 / 17:58:09 / cg"
   942 !
   950 !
   943 
   951 
   944 asFloat
   952 asFloat
   945 %{
   953     ^ self d0
   946     RETURN ( __MKFLOAT(__QuadDoubleInstPtr(self)->d_quadDoubleValue[0]) ); 
       
   947 %}
       
   948 
   954 
   949     "
   955     "
   950      (QDouble fromFloat:1.0) asFloat
   956      (QDouble fromFloat:1.0) asFloat
   951      (QDouble fromFloat:2.0) asFloat
   957      (QDouble fromFloat:2.0) asFloat
   952     "
   958     "
   953 
   959 
   954     "Created: / 12-06-2017 / 18:15:27 / cg"
   960     "Created: / 12-06-2017 / 18:15:27 / cg"
       
   961     "Modified: / 13-06-2017 / 17:56:50 / cg"
   955 !
   962 !
   956 
   963 
   957 coerce:aNumber
   964 coerce:aNumber
   958     "convert the argument aNumber into an instance of the receiver's class and return it."
   965     "convert the argument aNumber into an instance of the receiver's class and return it."
   959 
   966 
   970 
   977 
   971     "Created: / 12-06-2017 / 17:13:14 / cg"
   978     "Created: / 12-06-2017 / 17:13:14 / cg"
   972 !
   979 !
   973 
   980 
   974 negative
   981 negative
   975 %{
   982     ^ self d0 negative
   976     RETURN ( __QuadDoubleInstPtr(self)->d_quadDoubleValue[0] < 0 ? true : false ); 
       
   977 %}
       
   978 
   983 
   979     "
   984     "
   980      (QDouble fromFloat:0.0) negative
   985      (QDouble fromFloat:0.0) negative
   981      (QDouble fromFloat:1.0) negative
   986      (QDouble fromFloat:1.0) negative
   982      (QDouble fromFloat:-1.0) negative
   987      (QDouble fromFloat:-1.0) negative
   983     "
   988     "
   984 
   989 
   985     "Created: / 13-06-2017 / 01:57:39 / cg"
   990     "Created: / 13-06-2017 / 01:57:39 / cg"
       
   991     "Modified: / 13-06-2017 / 17:58:26 / cg"
   986 !
   992 !
   987 
   993 
   988 positive
   994 positive
   989 %{
   995     ^ self d0 positive
   990     RETURN ( __QuadDoubleInstPtr(self)->d_quadDoubleValue[0] >= 0 ? true : false ); 
       
   991 %}
       
   992 
   996 
   993     "
   997     "
   994      (QDouble fromFloat:1.0) positive
   998      (QDouble fromFloat:1.0) positive
   995      (QDouble fromFloat:-1.0) positive
   999      (QDouble fromFloat:-1.0) positive
   996     "
  1000     "
   997 
  1001 
   998     "Created: / 13-06-2017 / 01:56:53 / cg"
  1002     "Created: / 13-06-2017 / 01:56:53 / cg"
       
  1003     "Modified: / 13-06-2017 / 17:58:41 / cg"
   999 ! !
  1004 ! !
  1000 
  1005 
  1001 !QDouble methodsFor:'comparing'!
  1006 !QDouble methodsFor:'comparing'!
  1002 
  1007 
  1003 < aNumber
  1008 < aNumber
  1066                 && a[1] == b[1] 
  1071                 && a[1] == b[1] 
  1067                 && a[2] == b[2] 
  1072                 && a[2] == b[2] 
  1068                 && a[3] == b[3]) ? true : false);
  1073                 && a[3] == b[3]) ? true : false);
  1069     }
  1074     }
  1070 %}.
  1075 %}.
  1071     ^ super equalFromQDouble:aQDouble
  1076     ^ (aQDouble d0 = self d0)
       
  1077     and:[ (aQDouble d1 = self d1)
       
  1078     and:[ (aQDouble d2 = self d2)
       
  1079     and:[ (aQDouble d3 = self d3) ]]]
  1072     
  1080     
  1073     "
  1081     "
  1074      (QDouble fromFloat:1.0) = (QDouble fromFloat:1.0)
  1082      (QDouble fromFloat:1.0) = (QDouble fromFloat:1.0)
  1075      (QDouble fromFloat:1.0) = 1.0
  1083      (QDouble fromFloat:1.0) = 1.0
  1076      1.0 = (QDouble fromFloat:1.0)
  1084      1.0 = (QDouble fromFloat:1.0)
  1077    "
  1085    "
  1078 
  1086 
  1079     "Created: / 13-06-2017 / 03:01:19 / cg"
  1087     "Created: / 13-06-2017 / 03:01:19 / cg"
  1080     "Modified (comment): / 13-06-2017 / 08:43:45 / cg"
  1088     "Modified: / 13-06-2017 / 18:01:52 / cg"
  1081 !
  1089 !
  1082 
  1090 
  1083 lessFromQDouble:aQDouble
  1091 lessFromQDouble:aQDouble
  1084     "sent when aQDouble does not know how to compare to the receiver..
  1092     "sent when aQDouble does not know how to compare to the receiver..
  1085      Return true if aQDouble < self"
  1093      Return true if aQDouble < self"
  1213 
  1221 
  1214     "Created: / 13-06-2017 / 01:06:22 / cg"
  1222     "Created: / 13-06-2017 / 01:06:22 / cg"
  1215 !
  1223 !
  1216 
  1224 
  1217 quotientFromQDouble:aQDouble
  1225 quotientFromQDouble:aQDouble
       
  1226     "sloppy"
       
  1227     
  1218     |q0 q1 q2 q3 r|
  1228     |q0 q1 q2 q3 r|
  1219 
  1229 
  1220     q0 := self d0 / aQDouble d0.
  1230     q0 := self d0 / aQDouble d0.
  1221     r := self - (aQDouble * q0).
  1231     r := self - (aQDouble * q0).
  1222 
  1232 
  1225     
  1235     
  1226     q2 := r d0 / aQDouble d0.
  1236     q2 := r d0 / aQDouble d0.
  1227     r := r - (aQDouble * q2).
  1237     r := r - (aQDouble * q2).
  1228 
  1238 
  1229     q3 := r d0 / aQDouble d0.
  1239     q3 := r d0 / aQDouble d0.
  1230 %{
  1240 
  1231     {
  1241     r := self class d0:q0 d1:q1 d2:q2 d3:q3.
  1232         double _q0 = __floatVal(q0);
  1242     r renorm.
  1233         double _q1 = __floatVal(q1);
  1243     ^ r
  1234         double _q2 = __floatVal(q2);
       
  1235         double _q3 = __floatVal(q3);;
       
  1236         OBJ newQD;
       
  1237         
       
  1238         m_renorm4(_q0, _q1, _q2, _q3);
       
  1239         __qNew_qdReal(newQD, _q0, _q1, _q2, _q3);
       
  1240         RETURN( newQD );
       
  1241     }
       
  1242 %}.
       
  1243     ^ super quotientFromQDouble:aQDouble.
       
  1244 
  1244 
  1245     "
  1245     "
  1246      2.0 / (QDouble fromFloat:2.0)
  1246      2.0 / (QDouble fromFloat:2.0)
  1247      1e20 / (QDouble fromFloat:1.0)
  1247      1e20 / (QDouble fromFloat:1.0)
  1248      (2.0 / (QDouble fromFloat:1.0)) asFloat
  1248      (2.0 / (QDouble fromFloat:1.0)) asFloat
  1632 ! !
  1632 ! !
  1633 
  1633 
  1634 !QDouble methodsFor:'private accessing'!
  1634 !QDouble methodsFor:'private accessing'!
  1635 
  1635 
  1636 d0
  1636 d0
       
  1637     "the most significant (and highest valued) 53 bits of precision"
  1637 %{
  1638 %{
  1638     RETURN ( __MKFLOAT(__QuadDoubleInstPtr(self)->d_quadDoubleValue[0]) ); 
  1639     RETURN ( __MKFLOAT(__QuadDoubleInstPtr(self)->d_quadDoubleValue[0]) ); 
  1639 %}
  1640 %}
  1640 
  1641 
  1641     "Created: / 12-06-2017 / 20:15:12 / cg"
  1642     "Created: / 12-06-2017 / 20:15:12 / cg"
       
  1643     "Modified (comment): / 13-06-2017 / 17:59:47 / cg"
  1642 !
  1644 !
  1643 
  1645 
  1644 d1
  1646 d1
       
  1647     "the next most significant (and next highest valued) 53 bits of precision"
  1645 %{
  1648 %{
  1646     RETURN ( __MKFLOAT(__QuadDoubleInstPtr(self)->d_quadDoubleValue[1]) ); 
  1649     RETURN ( __MKFLOAT(__QuadDoubleInstPtr(self)->d_quadDoubleValue[1]) ); 
  1647 %}
  1650 %}
  1648 
  1651 
  1649     "Created: / 12-06-2017 / 20:15:12 / cg"
  1652     "Created: / 12-06-2017 / 20:15:12 / cg"
       
  1653     "Modified (comment): / 13-06-2017 / 18:00:00 / cg"
  1650 !
  1654 !
  1651 
  1655 
  1652 d2
  1656 d2
  1653 %{
  1657 %{
  1654     RETURN ( __MKFLOAT(__QuadDoubleInstPtr(self)->d_quadDoubleValue[2]) ); 
  1658     RETURN ( __MKFLOAT(__QuadDoubleInstPtr(self)->d_quadDoubleValue[2]) ); 
  1656 
  1660 
  1657     "Created: / 12-06-2017 / 20:15:29 / cg"
  1661     "Created: / 12-06-2017 / 20:15:29 / cg"
  1658 !
  1662 !
  1659 
  1663 
  1660 d3
  1664 d3
       
  1665     "the least significant (and smallest valued) 53 bits of precision"
  1661 %{
  1666 %{
  1662     RETURN ( __MKFLOAT(__QuadDoubleInstPtr(self)->d_quadDoubleValue[3]) ); 
  1667     RETURN ( __MKFLOAT(__QuadDoubleInstPtr(self)->d_quadDoubleValue[3]) ); 
  1663 %}
  1668 %}
  1664 
  1669 
  1665     "Created: / 12-06-2017 / 20:15:32 / cg"
  1670     "Created: / 12-06-2017 / 20:15:32 / cg"
       
  1671     "Modified (comment): / 13-06-2017 / 18:00:18 / cg"
       
  1672 !
       
  1673 
       
  1674 renorm
       
  1675 %{
       
  1676     double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue; 
       
  1677     double c0, c1, c2, c3;
       
  1678     OBJ newQD;
       
  1679 
       
  1680     c0 = a[0];
       
  1681     c1 = a[1];
       
  1682     c2 = a[2];
       
  1683     c3 = a[3];
       
  1684     m_renorm4(c0, c1, c2, c3);
       
  1685     a[0] = c0;
       
  1686     a[1] = c1;
       
  1687     a[2] = c2;
       
  1688     a[3] = c3;
       
  1689     RETURN( self );
       
  1690 %}.
       
  1691     ^ self error.
       
  1692 
       
  1693     "
       
  1694      (QDouble fromFloat:1.0) renorm
       
  1695     "
       
  1696 
       
  1697     "Created: / 13-06-2017 / 18:05:33 / cg"
  1666 ! !
  1698 ! !
  1667 
  1699 
  1668 !QDouble class methodsFor:'documentation'!
  1700 !QDouble class methodsFor:'documentation'!
  1669 
  1701 
  1670 version
  1702 version