#REFACTORING by exept
class: QDouble
comment/format in: #mantissa
class: QDouble class
comment/format in: #coerce:
--- a/QDouble.st Sun Dec 01 05:17:07 2019 +0100
+++ b/QDouble.st Sun Dec 01 05:25:38 2019 +0100
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
"
COPYRIGHT (c) 2017 by eXept Software AG
All Rights Reserved
@@ -16,11 +14,11 @@
"{ NameSpace: Smalltalk }"
LimitedPrecisionReal variableByteSubclass:#QDouble
- instanceVariableNames:''
- classVariableNames:'DefaultPrintFormat E Epsilon FMax FMin InvFact Ln10 Ln2 NaN Pi
- QDoubleOne QDoubleZero'
- poolDictionaries:''
- category:'Magnitude-Numbers'
+ instanceVariableNames:''
+ classVariableNames:'DefaultPrintFormat E Epsilon FMax FMin InvFact Ln10 Ln2 NaN Pi
+ QDoubleOne QDoubleZero'
+ poolDictionaries:''
+ category:'Magnitude-Numbers'
!
!QDouble primitiveDefinitions!
@@ -475,6 +473,7 @@
}
#if 0
+
static INLINE void
two_prod(double *p, double *e, double a, double b)
{
@@ -491,8 +490,10 @@
e[0] = ((ah*bh - p[0]) + ah*bl + al*bh) + al*bl;
}
+
#else
-static INLINE double
+
+static INLINE void
two_prod(double *o, double *e, double a, double b) {
double a_hi, a_lo, b_hi, b_lo;
double p = a * b;
@@ -501,6 +502,7 @@
e[0] = ((a_hi * b_hi - p) + a_hi * b_lo + a_lo * b_hi) + a_lo * b_lo;
o[0] = p;
}
+
#endif
#if 0
@@ -2990,7 +2992,7 @@
!QDouble class methodsFor:'coercing & converting'!
coerce:aNumber
- "convert the argument aNumber into an instance of the receiver's class and return it."
+ "convert the argument aNumber into an instance of the receiver (class) and return it."
^ aNumber asQDouble
@@ -3655,6 +3657,11 @@
-12345.0 asQDouble mantissa -> -0.75347900390625
(1e40 + 1e-40) asQDouble exponent -> 133
(1e40 + 1e-40) asQDouble mantissa -> 0.918354961579912
+
+ self assert:(1.0 asQDouble mantissa * (2 raisedTo:1.0 asQDouble exponent)) = 1.0 asQDouble.
+ self assert:(100.0 asQDouble mantissa * (2 raisedTo:100.0 asQDouble exponent)) = 100.0 asQDouble.
+ self assert:(10e15 asQDouble mantissa * (2 raisedTo:10e15 asQDouble exponent)) = 10e15 asQDouble.
+ self assert:(10e-15 asQDouble mantissa * (2 raisedTo:10e-15 asQDouble exponent)) = 10e-15 asQDouble.
"
"Created: / 20-06-2017 / 11:06:02 / cg"
@@ -4103,18 +4110,6 @@
"Modified: / 03-07-2017 / 23:09:11 / cg"
! !
-!QDouble methodsFor:'inspecting'!
-
-inspectorExtraAttributes
- "extra (pseudo instvar) entries to be shown in an inspector."
-
- ^ super inspectorExtraAttributes
- add:'-{doubles}' -> [ self asDoubleArray printString ];
- yourself
-
- "Created: / 12-06-2017 / 23:43:05 / cg"
- "Modified (format): / 18-07-2017 / 19:54:48 / cg"
-! !
!QDouble methodsFor:'mathematical functions'!
@@ -4854,18 +4849,18 @@
/* Third double is already an integer. */
x3 = nint(a[3]);
} else {
- if (abs(x2 - a[2]) == 0.5 && a[3] < 0.0) {
+ if (fabs(x2 - a[2]) == 0.5 && a[3] < 0.0) {
x2 -= 1.0;
}
}
} else {
- if (abs(x1 - a[1]) == 0.5 && a[2] < 0.0) {
+ if (fabs(x1 - a[1]) == 0.5 && a[2] < 0.0) {
x1 -= 1.0;
}
}
} else {
/* First double is not an integer. */
- if (abs(x0 - a[0]) == 0.5 && a[1] < 0.0) {
+ if (fabs(x0 - a[0]) == 0.5 && a[1] < 0.0) {
x0 -= 1.0;
}
}
@@ -5289,3 +5284,4 @@
version_CVS
^ '$Header$'
! !
+