06-04-2014, 02:52 PM
@Pauli: Assuming my 27x x^2 and 27x POWPOW based tests give the same results as the wp34s, can I derive from that my trig implementation is a little bit more precise than yours?
(06-01-2014 11:57 AM)Tugdual Wrote: [ -> ](06-01-2014 07:32 AM)Thomas Klemm Wrote: [ -> ]The WP-34S however uses:Interesting, I wonder what justified the choice.
Code:
// Now Taylor series
// tan(x) = x(1-x^2/3+x^4/5-x^6/7...)
A matter of patent?
What is the most efficient approach in terms of speed and accuracy between CORDIC and Taylor?
Or may be CORDIC was the right choice for old calculators with little ROM?
(06-03-2014 02:02 PM)pito Wrote: [ -> ]I've flashed my CM3 with the old stuff I've found - when running below code with 34digits I get (I've added your result for comparison):
Code:
TRIG9
TRIG9= 9.000 000 000 000 000 000 000 000 000 000 227
yours: 8.999 999 999 999 999 999 999 999 999 937 535
Elapsed x1 =201 ms
Code:
#define _PI "3.1415926535897932384626433832795028841971693993751"
// TRIG9 PRECISION TEST
cout<<"TRIG9"<<endl;
decfp tmp, PI;
PI = _PI;
tmp = "9.0"; // 9 DEGREE
// deg to rad
timer = millis;
tmp = tmp * PI / "180.0";
tmp = arcsin ( arccos ( arctan ( tan ( cos ( sin ( tmp ) ) ) ) ) ) ;
// rad to deg
tmp = tmp * "180.0" / PI;
timer = millis - timer;
cout<<"TRIG9= "<<tmp<<endl;
cout<<"Elapsed x1 ="<<timer<<" ms"<<endl;
But I've learned you do rounding after each calculation so maybe that is what makes the diff..
Quote:I recently implemented from scratch all the transcendental functions using CORDICOn which hw platform your implementation runs (cpu)?
Quote:But how do we know right from wrong?The 9 degree test:
(06-04-2014 06:06 PM)pito Wrote: [ -> ]Quote:I recently implemented from scratch all the transcendental functions using CORDICOn which hw platform your implementation runs (cpu)?
(06-04-2014 06:06 PM)pito Wrote: [ -> ]Quote:But how do we know right from wrong?The 9 degree test:
The windows calculator (most probably decNumber lib 34+) gives you 9.0
Wolfram's alfa online gives you 9.0
Quote:libmpdec - C/C++ library
libmpdec is a complete implementation of the General Decimal Arithmetic Specification. The specification, written by Mike Cowlishaw from IBM, defines a general purpose arbitrary precision data type together with rigorously specified functions and rounding behavior. As described in the scope section of the specification, libmpdec will - with minor restrictions - also conform to the IEEE 754-2008 Standard for Floating-Point Arithmetic, provided that the appropriate context parameters are set...
(06-04-2014 06:30 PM)pito Wrote: [ -> ]WP34s calc and various other arbitrary precision decimal fp libs/wrappers are using the IBM's decNumber library (which sets the standards). There are some settings for the rounding inside (context something), I never messed with them in detail, though. Maybe the difference between the results is related to the proper rounding settings know how within the library..
0.15707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533
0.15643446504023086901010531946716689231389989208566079008464134605775879330562357933669587267684868837514030084768044693
0.98778906148432102659224597185688635535644304386604962178575139117322922155888385891561054646005957655720326772574833859
1.51635755259120721369527452363141276164707213917447847214843599362575833442796023036122220616360602112239375025366785886
0.98778906148432102659224597185688635535644304386604962178575139117322922155888385891561054646005957655720326772574833858
0.15643446504023086901010531946716689231389989208566079008464134605775879330562357933669587267684868837514030084768044700
0.15707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411539
9.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000330
0.157079632679489661923132169163975
0.156434465040230869010105319467166
0.987789061484321026592245971856886
1.516357552591207213695274523631411
0.987789061484321026592245971856885
0.156434465040230869010105319467175
0.157079632679489661923132169163983
9.000000000000000000000000000000450
0.157079632679489661923132169163975
0.156434465040230869010105319467167
0.987789061484321026592245971856886
1.516357552591207213695274523631412
0.987789061484321026592245971856886
0.156434465040230869010105319467169
0.157079632679489661923132169163977
9.000000000000000000000000000000106
(06-04-2014 07:16 PM)pito Wrote: [ -> ]This is the entire sequence from wolfram's alfa (120digits):
Code:
0.15707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533
0.15643446504023086901010531946716689231389989208566079008464134605775879330562357933669587267684868837514030084768044693
0.98778906148432102659224597185688635535644304386604962178575139117322922155888385891561054646005957655720326772574833859
1.51635755259120721369527452363141276164707213917447847214843599362575833442796023036122220616360602112239375025366785886
0.98778906148432102659224597185688635535644304386604962178575139117322922155888385891561054646005957655720326772574833858
0.15643446504023086901010531946716689231389989208566079008464134605775879330562357933669587267684868837514030084768044700
0.15707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411539
9.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000330
round(asin(round(acos(round(atan(round(tan(round(cos(round(sin(round(round(9*round(pi*10^33))/18)*10^-34)*10^34)*10^-34)*10^34)*10^-34)*10^34)*10^-34)*10^34)*10^-34)*10^34)*10^-34)*10^34)*10^-34
round(round((0.1570796326794896619231321691639748/round(pi*10^33)*10^33)*10^35)*10^-35 * 180 * 10^33)*10^-33
(06-04-2014 07:30 PM)pito Wrote: [ -> ]This is 34digits not rounded
[code]0.157079632679489661923132169163975
0.156434465040230869010105319467166
0.987789061484321026592245971856886
1.516357552591207213695274523631411
0.157079632679489661923132169163975
0.156434465040230869010105319467167
0.987789061484321026592245971856886
1.51635755259120721369527452363141
0.987789061484321026592245971856886
0.156434465040230869010105319467169
0.157079632679489661923132169163977
9.00000000000000000000000000000011
8.99999999999999999999999999999999999
8.9999999999999999999999999999999999999999999999999999999
180/pi*(asin(acos(atan(tan(cos(sin((9.0+epsilon)*pi/180)))))))
epsilon = -1e-36
8.999999999999999999999999999999999999
epsilon = -1e-35
8.99999999999999999999999999999999999
epsilon = -1e-34
8.9999999999999999999999999999999999
epsilon = 0
9.0
epsilon = 1e-34
9.0000000000000000000000000000000001
epsilon = 1e-35
9.00000000000000000000000000000000001
epsilon = 1e-36
9.000000000000000000000000000000000001
(06-04-2014 07:51 PM)pito Wrote: [ -> ]Yea, it seems it is an extra, but the 1 at the end is not a big diff, maybe
Do you mean (recalculated, rounded):
Code:
0.157079632679489661923132169163975
0.156434465040230869010105319467167
0.987789061484321026592245971856886
1.51635755259120721369527452363141
0.987789061484321026592245971856886
0.156434465040230869010105319467169
0.157079632679489661923132169163977
9.00000000000000000000000000000011
(06-04-2014 08:34 PM)pito Wrote: [ -> ]I did following experiment when entering the 9degree formula in the wolfram - I added a small epsilon to the 9:
Based on this result I think wolfram optimizes out the formula entered.Code:
180/pi*(asin(acos(atan(tan(cos(sin((9.0+epsilon)*pi/180)))))))
epsilon = -1e-36
8.999999999999999999999999999999999999
epsilon = -1e-35
8.99999999999999999999999999999999999
epsilon = -1e-34
8.9999999999999999999999999999999999
epsilon = 0
9.0
epsilon = 1e-34
9.0000000000000000000000000000000001
epsilon = 1e-35
9.00000000000000000000000000000000001
epsilon = 1e-36
9.000000000000000000000000000000000001
0.1570796326794896619231321691639751
0.1564344650402308690101053194671668
0.9877890614843210265922459718568864
1.516357552591207213695274523631413
0.9877890614843210265922459718568864
0.1564344650402308690101053194671666
0.1570796326794896619231321691639748
8.999999999999999999999999999999980
(06-04-2014 09:21 PM)pito Wrote: [ -> ]Wolfram alfa, 34digits (hopefully), rounded:
Code:
0.1570796326794896619231321691639751
0.1564344650402308690101053194671668
0.9877890614843210265922459718568864
1.516357552591207213695274523631413
0.9877890614843210265922459718568864
0.1564344650402308690101053194671666
0.1570796326794896619231321691639748
8.999999999999999999999999999999980
Quote:TRIG9
TRIG9= 9.000 000 000 000 000 000 000 000 000 000 227
yours: 8.999 999 999 999 999 999 999 999 999 937 535
Elapsed x1 =201 ms