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.
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.
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 =============================================================================*/
21 /*============================================================================
22 * Written for Bochs (x86 achitecture simulator) by
23 * Stanislav Shwartsman [sshwarts at sourceforge net]
24 * ==========================================================================*/
29 #include "softfloat.h"
32 // f(x) ~ C + (C * x) + (C * x) + (C * x) + (C * x) + ... + (C * x)
36 // p(x) = > C * x q(x) = > C * x
39 // f(x) ~ [ p(x) + x * q(x) ]
42 float128
EvalPoly(float128 x
, float128
*arr
, unsigned n
, float_status_t
&status
)
44 float128 x2
= float128_mul(x
, x
, status
);
49 float128 r1
= arr
[--n
];
52 r1
= float128_mul(r1
, x2
, status
);
54 r1
= float128_add(r1
, arr
[i
], status
);
56 if (i
) r1
= float128_mul(r1
, x
, status
);
58 float128 r2
= arr
[--n
];
61 r2
= float128_mul(r2
, x2
, status
);
63 r2
= float128_add(r2
, arr
[i
], status
);
65 if (i
) r2
= float128_mul(r2
, x
, status
);
67 return float128_add(r1
, r2
, status
);
71 // f(x) ~ C + (C * x) + (C * x) + (C * x) + (C * x) + ... + (C * x)
75 // p(x) = > C * x q(x) = > C * x
79 // f(x) ~ [ p(x) + x * q(x) ]
82 float128
EvenPoly(float128 x
, float128
*arr
, unsigned n
, float_status_t
&status
)
84 return EvalPoly(float128_mul(x
, x
, status
), arr
, n
, status
);
88 // f(x) ~ (C * x) + (C * x) + (C * x) + (C * x) + (C * x) + ... + (C * x)
91 // = x * [ C + (C * x) + (C * x) + (C * x) + (C * x) + ... + (C * x)
95 // p(x) = > C * x q(x) = > C * x
99 // f(x) ~ x * [ p(x) + x * q(x) ]
102 float128
OddPoly(float128 x
, float128
*arr
, unsigned n
, float_status_t
&status
)
104 return float128_mul(x
, EvenPoly(x
, arr
, n
, status
), status
);