f80poly.inc 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. { The code is translated from Bochs by Florian Klaempfl and contains
  2. the copyright notice below. The original filename is poly.cc
  3. All changes to the code are copyrighted by the Free Pascal development team and
  4. released under the same license as the orginal code, see below.
  5. }
  6. {============================================================================
  7. This source file is an extension to the SoftFloat IEC/IEEE Floating-point
  8. Arithmetic Package, Release 2b, written for Bochs (x86 achitecture simulator)
  9. floating point emulation.
  10. THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has
  11. been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES
  12. RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS
  13. AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES,
  14. COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE
  15. EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE
  16. INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR
  17. OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE.
  18. Derivative works are acceptable, even for commercial purposes, so long as
  19. (1) the source code for the derivative work includes prominent notice that
  20. the work is derivative, and (2) the source code includes prominent notice with
  21. these four paragraphs for those parts of this code that are retained.
  22. =============================================================================}
  23. {============================================================================
  24. * Written for Bochs (x86 achitecture simulator) by
  25. * Stanislav Shwartsman [sshwarts at sourceforge net]
  26. * ==========================================================================}
  27. { the pascal translation is based on https://github.com/lubomyr/bochs/blob/8e0b9abcd81cd24d4d9c68f7fdef2f53bc180d33/cpu/fpu/poly.cc
  28. if you update it, please make a note here
  29. Translation notes:
  30. * the use of status paramteters has been removed, this is handled directly by the status variable
  31. }
  32. {$define FLOAT128}
  33. // 2 3 4 n
  34. // f(x) ~ C + (C * x) + (C * x) + (C * x) + (C * x) + ... + (C * x)
  35. // 0 1 2 3 4 n
  36. //
  37. // -- 2k -- 2k+1
  38. // p(x) = > C * x q(x) = > C * x
  39. // -- 2k -- 2k+1
  40. //
  41. // f(x) ~ [ p(x) + x * q(x) ]
  42. //
  43. function EvalPoly(x: float128; arr: pfloat128; n: Integer): float128;
  44. var
  45. r: float128;
  46. begin
  47. dec(n);
  48. r := arr[n];
  49. repeat
  50. r := float128_mul(r, x);
  51. dec(n);
  52. r := float128_add(r, arr[n]);
  53. until not(n > 0);
  54. Result := r;
  55. end;
  56. // 2 4 6 8 2n
  57. // f(x) ~ C + (C * x) + (C * x) + (C * x) + (C * x) + ... + (C * x)
  58. // 0 1 2 3 4 n
  59. //
  60. // -- 4k -- 4k+2
  61. // p(x) = > C * x q(x) = > C * x
  62. // -- 2k -- 2k+1
  63. //
  64. // 2
  65. // f(x) ~ [ p(x) + x * q(x) ]
  66. //
  67. function EvenPoly(x: float128; arr: pfloat128; n: Integer): float128;
  68. begin
  69. Result := EvalPoly(float128_mul(x, x), arr, n);
  70. end;
  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. function OddPoly(x: float128; arr: pfloat128; n: Integer) : float128;
  86. begin
  87. Result := float128_mul(x, EvenPoly(x, arr, n));
  88. end;