home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 2.ddi / MATHSRC.ZIP / POLYL.CAS < prev    next >
Encoding:
Text File  |  1992-06-10  |  2.8 KB  |  97 lines

  1. /*------------------------------------------------------------------------
  2.  * filename - polyl.cas
  3.  *
  4.  * function(s)
  5.  *        polyl - generates a long double polynomial from arguments
  6.  *-----------------------------------------------------------------------*/
  7.  
  8. /*
  9.  *      C/C++ Run Time Library - Version 5.0
  10.  *
  11.  *      Copyright (c) 1987, 1992 by Borland International
  12.  *      All Rights Reserved.
  13.  *
  14.  */
  15.  
  16.  
  17. #pragma inline
  18. #include <asmrules.h>
  19.  
  20. #include <_math.h>
  21. #include <math.h>
  22. #include <errno.h>
  23.  
  24. /*--------------------------------------------------------------------------*
  25.  
  26. Name            polyl - generates a polynomial from arguments
  27.  
  28. Usage           long double     polyl(long double x, int n, long double c []);
  29.  
  30. Prototype in    math.h
  31.  
  32. Description     polyl  generates  a  polynomial in  x,  of  degree  n, with
  33.                 coefficients c[0],  c[1], ..., c[n].  For example, if  n=4,
  34.                 the generated polynomial is
  35.  
  36.                         c[4].x^4 + c[3].x^3 + c[2].x^2] + c[1].x + c[0]
  37.  
  38.                 The polynomial is calculated using Horner's method:
  39.  
  40.                         polylnom = (..((x.c[n] + c[n-1]).x + c[n-2])..).x + c[0]
  41.  
  42. Return value    polyl returns the  value of the polynomial as  evaluated for
  43.                 the given x.
  44.                 If n < 0  then the result is a domain error.
  45.                 A range error occurs if the result exceeds long double range.
  46.  
  47. *---------------------------------------------------------------------------*/
  48. #pragma warn -rvl
  49. #pragma warn -use
  50. long double     polyl (long double x, int n, long double c [])
  51. {
  52.         volatile unsigned    sw;
  53.  
  54. asm     FLD     LONGDOUBLE (x)
  55. asm     mov     si, n
  56. asm     shl     si, 1
  57. asm     shl     si, 1
  58. asm     add     si, n
  59. asm     shl     si, 1
  60.         /* si = 10*n */
  61. asm     jl      ply_domain
  62. asm     LES_    bx, c
  63. asm     FLD     LONGDOUBLE (ES_ [bx+si])        /* get Nth coefficient */
  64. asm     jz      short   ply_end                 /* if n=0, we're done */
  65.  
  66. ply_loop:
  67. asm     FMUL    ST, ST(1)                       /* x*c[n] */
  68. asm     sub     si, 10                          /* n-- */
  69. asm     FLD     LONGDOUBLE (ES_ [bx+si])        /* get next coefficient */
  70. asm     FADD
  71. asm     jg      ply_loop
  72.  
  73. ply_end:
  74. asm     FXAM
  75. asm     FSTSW   W0 (sw)
  76. asm     FSTP    ST(1)                   /* discard ST(1) */
  77. asm     mov     ax, sw
  78. asm     sahf
  79. asm     jc      ply_range
  80.         return;
  81.  
  82. ply_domain:
  83. asm     mov     si, DOMAIN
  84. asm     jmp     short   ply_err
  85.  
  86. ply_range:
  87. asm     mov     si, OVERFLOW
  88.  
  89. ply_err:
  90. asm     FSTP    ST(0)                   /* discard ST */
  91. #pragma warn -ret
  92.         return  __matherrl (_SI, "polyl", &x, c, _LHUGE_VAL);
  93. #pragma warn .ret
  94. }
  95. #pragma warn .rvl
  96. #pragma warn .use
  97.