1 /*============================================================================
2 This source file is an extension to the SoftFloat IEC/IEEE Floating-point
3 Arithmetic Package, Release 2b, written for Bochs (x86 achitecture simulator)
4 floating point emulation.
5 
6 THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE.  Although reasonable effort has
7 been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES
8 RESULT IN INCORRECT BEHAVIOR.  USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS
9 AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES,
10 COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE
11 EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE
12 INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR
13 OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE.
14 
15 Derivative works are acceptable, even for commercial purposes, so long as
16 (1) the source code for the derivative work includes prominent notice that
17 the work is derivative, and (2) the source code includes prominent notice with
18 these four paragraphs for those parts of this code that are retained.
19 =============================================================================*/
20 
21 /*============================================================================
22  * Written for Bochs (x86 achitecture simulator) by
23  *            Stanislav Shwartsman [sshwarts at sourceforge net]
24  * ==========================================================================*/
25 
26 #define FLOAT128
27 
28 #include <assert.h>
29 #include "softfloat.h"
30 
31 //                            2         3         4               n
32 // f(x) ~ C + (C * x) + (C * x) + (C * x) + (C * x) + ... + (C * x)
33 //         0    1         2         3         4               n
34 //
35 //          --       2k                --        2k+1
36 //   p(x) = >  C  * x           q(x) = >  C   * x
37 //          --  2k                     --  2k+1
38 //
39 //   f(x) ~ [ p(x) + x * q(x) ]
40 //
41 
EvalPoly(float128 x,float128 * arr,int n,float_status_t & status)42 float128 EvalPoly(float128 x, float128 *arr, int n, float_status_t &status)
43 {
44     float128 r = arr[--n];
45 
46     do {
47         r = float128_mul(r, x, status);
48         r = float128_add(r, arr[--n], status);
49     } while (n > 0);
50 
51     return r;
52 }
53 
54 //                  2         4         6         8               2n
55 // f(x) ~ C + (C * x) + (C * x) + (C * x) + (C * x) + ... + (C * x)
56 //         0    1         2         3         4               n
57 //
58 //          --       4k                --        4k+2
59 //   p(x) = >  C  * x           q(x) = >  C   * x
60 //          --  2k                     --  2k+1
61 //
62 //                    2
63 //   f(x) ~ [ p(x) + x * q(x) ]
64 //
65 
EvenPoly(float128 x,float128 * arr,int n,float_status_t & status)66 float128 EvenPoly(float128 x, float128 *arr, int n, float_status_t &status)
67 {
68      return EvalPoly(float128_mul(x, x, status), arr, n, status);
69 }
70 
71 //                        3         5         7         9               2n+1
72 // f(x) ~ (C * x) + (C * x) + (C * x) + (C * x) + (C * x) + ... + (C * x)
73 //          0         1         2         3         4               n
74 //                        2         4         6         8               2n
75 //      = x * [ C + (C * x) + (C * x) + (C * x) + (C * x) + ... + (C * x)
76 //               0    1         2         3         4               n
77 //
78 //          --       4k                --        4k+2
79 //   p(x) = >  C  * x           q(x) = >  C   * x
80 //          --  2k                     --  2k+1
81 //
82 //                        2
83 //   f(x) ~ x * [ p(x) + x * q(x) ]
84 //
85 
OddPoly(float128 x,float128 * arr,int n,float_status_t & status)86 float128 OddPoly(float128 x, float128 *arr, int n, float_status_t &status)
87 {
88      return float128_mul(x, EvenPoly(x, arr, n, status), status);
89 }
90