123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- { The code is translated from Bochs by Florian Klaempfl and contains
- the copyright notice below. The original filename is poly.cc
- All changes to the code are copyrighted by the Free Pascal development team and
- released under the same license as the orginal code, see below.
- }
- {============================================================================
- This source file is an extension to the SoftFloat IEC/IEEE Floating-point
- Arithmetic Package, Release 2b, written for Bochs (x86 achitecture simulator)
- floating point emulation.
- THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has
- been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES
- RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS
- AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES,
- COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE
- EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE
- INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR
- OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE.
- Derivative works are acceptable, even for commercial purposes, so long as
- (1) the source code for the derivative work includes prominent notice that
- the work is derivative, and (2) the source code includes prominent notice with
- these four paragraphs for those parts of this code that are retained.
- =============================================================================}
- {============================================================================
- * Written for Bochs (x86 achitecture simulator) by
- * Stanislav Shwartsman [sshwarts at sourceforge net]
- * ==========================================================================}
- { the pascal translation is based on https://github.com/lubomyr/bochs/blob/8e0b9abcd81cd24d4d9c68f7fdef2f53bc180d33/cpu/fpu/poly.cc
- if you update it, please make a note here
- Translation notes:
- * the use of status paramteters has been removed, this is handled directly by the status variable
- }
- {$define FLOAT128}
- // 2 3 4 n
- // f(x) ~ C + (C * x) + (C * x) + (C * x) + (C * x) + ... + (C * x)
- // 0 1 2 3 4 n
- //
- // -- 2k -- 2k+1
- // p(x) = > C * x q(x) = > C * x
- // -- 2k -- 2k+1
- //
- // f(x) ~ [ p(x) + x * q(x) ]
- //
- function EvalPoly(x: float128; arr: pfloat128; n: Integer): float128;
- var
- r: float128;
- begin
- dec(n);
- r := arr[n];
- repeat
- r := float128_mul(r, x);
- dec(n);
- r := float128_add(r, arr[n]);
- until not(n > 0);
- Result := r;
- end;
- // 2 4 6 8 2n
- // f(x) ~ C + (C * x) + (C * x) + (C * x) + (C * x) + ... + (C * x)
- // 0 1 2 3 4 n
- //
- // -- 4k -- 4k+2
- // p(x) = > C * x q(x) = > C * x
- // -- 2k -- 2k+1
- //
- // 2
- // f(x) ~ [ p(x) + x * q(x) ]
- //
- function EvenPoly(x: float128; arr: pfloat128; n: Integer): float128;
- begin
- Result := EvalPoly(float128_mul(x, x), arr, n);
- end;
- // 3 5 7 9 2n+1
- // f(x) ~ (C * x) + (C * x) + (C * x) + (C * x) + (C * x) + ... + (C * x)
- // 0 1 2 3 4 n
- // 2 4 6 8 2n
- // = x * [ C + (C * x) + (C * x) + (C * x) + (C * x) + ... + (C * x)
- // 0 1 2 3 4 n
- //
- // -- 4k -- 4k+2
- // p(x) = > C * x q(x) = > C * x
- // -- 2k -- 2k+1
- //
- // 2
- // f(x) ~ x * [ p(x) + x * q(x) ]
- //
- function OddPoly(x: float128; arr: pfloat128; n: Integer) : float128;
- begin
- Result := float128_mul(x, EvenPoly(x, arr, n));
- end;
|