--- a/QDouble.st Wed Jun 21 20:50:27 2017 +0200
+++ b/QDouble.st Thu Jun 22 14:33:26 2017 +0200
@@ -1922,10 +1922,17 @@
"
2.0 exp -> 7.38905609893065
2.0 asQDouble exp -> 7.38905609893065022723
+
+ 2 asQDouble exp printfPrintString:'%70.68f'
+ -> 7.389056098930650227230427460575007813180315570551847324087127822432669
+
+ actual result:
+ -> 7.3890560989306502272304274605750078131803155705518473240871278225225737960790577633843124850791217947737531612654...
+
"
"Created: / 19-06-2017 / 01:49:32 / cg"
- "Modified (comment): / 21-06-2017 / 13:50:38 / cg"
+ "Modified (comment): / 22-06-2017 / 14:32:53 / cg"
!
exp_sloppy
@@ -2105,6 +2112,9 @@
!
ln
+ "return the natural logarithm of myself.
+ Raises an exception, if the receiver is less or equal to zero."
+
|d0 x|
d0 := self d0.
@@ -2126,19 +2136,36 @@
"/ initial approx.
x := d0 ln asQDouble.
"/ three more iterations of taylor
- x := x + (self * (x negated exp)) - 1.0.
- x := x + (self * (x negated exp)) - 1.0.
- x := x + (self * (x negated exp)) - 1.0.
+ x := x + (self / (x exp)) - 1.0.
+ x := x + (self / (x exp)) - 1.0.
+ x := x + (self / (x exp)) - 1.0.
^ x
"
-1 ln
+
1.0 asQDouble ln
+
+ 3.0 ln printfPrintString:'%60.58lf'
+ -> 1.0986122886681097821082175869378261268138885498046875000000'
+ ^
+
+ 3.0 asQDouble ln printfPrintString:'%60.58f'
+ -> 1.0986122886681096913952452369225257046474905578227494517347
+
+ (3.0 asQDouble ln_withAccuracy:1e-60) printfPrintString:'%60.58f'
+ -> 1.0986122886681096913952452369225257046474905578227494517347
+
+ (3.0 asQDouble ln_withAccuracy:1e-60) printfPrintString:'%70.68f'
+ -> 1.09861228866810969139524523692252570464749055782274945173469406224775
+
+ actual result:
+ -> 1.0986122886681096913952452369225257046474905578227494517346943336374942932186089668736157548137320887879700290659...
"
"Created: / 18-06-2017 / 23:32:54 / cg"
- "Modified (comment): / 19-06-2017 / 19:01:25 / cg"
+ "Modified (comment): / 22-06-2017 / 14:33:11 / cg"
!
negated
@@ -2160,7 +2187,43 @@
"Modified (comment): / 12-06-2017 / 23:46:57 / cg"
!
+sqrt
+ "Return the square root of the receiver"
+
+ "this computes a roughly 65 digits precision result,
+ using sqrt from the double as an initial guess"
+
+ |guess|
+
+ guess := self asFloat sqrt asQDouble.
+ ^ self sqrt_withAccuracy:self epsilon fromInitialGuess:(self / 2)
+
+ "FloatD is only correct in roughly 17 digits
+
+ 2 sqrt printfPrintString:'%50.48f'
+ -> 1.414213562373095145474621858738828450441360473633
+ ^
+ QDouble gives you much more:
+
+ 2 asQDouble sqrt printfPrintString:'%50.48f'
+ -> 1.414213562373095048801688724209698078569671875377
+
+ 2 asQDouble sqrt printfPrintString:'%60.58f'
+ -> 1.4142135623730950488016887242096980785696718753769480731767'
+
+ 2 asQDouble sqrt printfPrintString:'%70.68f'
+ -> 1.41421356237309504880168872420969807856967187537694807317667973799602
+
+ actual digits:
+ -> 1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727350138462309...
+ "
+
+ "Created: / 22-06-2017 / 13:53:47 / cg"
+!
+
squared
+ "return receiver * receiver"
+
%{
double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
double p0, p1, p2, p3, p4, p5;
@@ -2170,6 +2233,8 @@
double t;
OBJ newQD;
+ // code makes use of some symetries to avoid a few multiplications...
+
m_two_sqr(p0, a[0], q0);
t = 2.0 * a[0];
@@ -2216,6 +2281,7 @@
"
"Created: / 13-06-2017 / 01:27:58 / cg"
+ "Modified: / 22-06-2017 / 14:08:31 / cg"
! !
!QDouble methodsFor:'printing & storing'!