home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / asm32 / solve.doc < prev    next >
Text File  |  1993-09-12  |  22KB  |  777 lines

  1.  
  2. *********************** MATHEMATICAL SOLUTIONS *****************************
  3.  
  4. ASM32's SOLVE subroutines are handy for many number crunching problems.
  5. Most SOLVE subroutines require a math coprocessor.  In subroutines
  6. requiring a math coprocessor, the coprocessor must have been initialized
  7. with FINIT or FNINIT before calling the subroutine.  See MathChip in
  8. SYSTEM.DOC.  Note that the 80x87 math coprocessors do not understand
  9. unsigned integers.
  10.  
  11.  
  12. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  13.  
  14. C2F:        convert degrees Celcius to degrees Fahrenheit
  15. Source:     f2c.asm
  16.  
  17. 80x87 required
  18.  
  19. Call with:  ST(0) = degrees Celcius
  20. Returns:    ST(0) = degrees Fahrenheit
  21. Uses:       ST(0), 80x87 flags
  22. Example:
  23.  
  24. include code32.inc
  25.  
  26. extrn   c2f:near
  27.  
  28. ; data
  29. c0      dw 100           ; 100 degrees Celcius
  30. f0      dw ?             ; going to store degrees Fahrenheit here
  31.  
  32. ; code
  33.         .
  34.         .
  35.         .
  36.         fild   c0        ; load degrees Celcius into ST(0)
  37.         call   c2f       ; returns degrees Fahrenheit in ST(0)
  38.         fistp  f0        ; save degrees Fahrenheit and pop the 8087's stack
  39.  
  40.  
  41.  
  42. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  43.  
  44. CUBEFITF4:  fit a cubic equation to a set of float4 data
  45. CUBEFITF8:  fit a cubic equation to a set of float8 data
  46. CUBEFITI2:  fit a cubic equation to a set of integer2 data
  47. CUBEFITI4:  fit a cubic equation to a set of integer4 data
  48. Source:     cubefit.asm
  49.  
  50. 80x87 required
  51.  
  52.             CubeFit subroutines use the Least Squares method to calculate
  53.             the a, b, c and d coefficients of the equation
  54.  
  55.             y = a + bx + c(x^2) + d(x^3)
  56.  
  57.             which best fits the given data points.  See also QuadFit and
  58.             LineFit.
  59.             The data series at DS:[BX] consists of n sets of x and y
  60.             coordinates.
  61.  
  62. Call with:  EBX pointing to data series
  63.             ECX = number of (x,y) points
  64. Returns:    ST(0) = a
  65.             ST(1) = b
  66.             ST(2) = c
  67.             ST(3) = d
  68. Uses:       entire 80x87 stack
  69. Example:
  70.  
  71. include code32.inc
  72.  
  73. extrn   cubefiti2:near
  74.  
  75. ; data
  76. points  dw 1,6           ; first (x,y) coordinate pair: x0 = 1, y0 = 6
  77.         dw 2,17          ; x1 = 2, y1 = 17
  78.         dw 5,86          ; x2 = 5, y2 = 86
  79.         dw 4,57          ; x3 = 4, y3 = 57
  80.         dw 3,34          ; x4 = 3, y4 = 34
  81. n equ ($-points) shr 2   ; number of coordinate pairs (5 in this case)
  82.  
  83. ; code
  84.         .
  85.         .
  86.         .
  87.         lea   ebx,points  ; point to data series
  88.         mov   ecx,n       ; 5 data points
  89.         call  cubefiti2   ; returns ST(0) = a
  90.                           ;         ST(1) = b
  91.                           ;         ST(2) = c
  92.                           ;         ST(3) = d
  93.  
  94.  
  95.  
  96. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  97.  
  98. DEG2RAD:    convert degrees of arc to radians
  99. Source:     deg2rad.asm
  100.  
  101. 80x87 required
  102.  
  103. Call with:  ST(0) = degrees of arc
  104. Returns:    ST(0) = radians
  105. Uses:       80x87 stack - ST(6) and ST(7) are lost
  106. Example:
  107.  
  108. include code32 .inc
  109.  
  110. extrn   deg2rad:near
  111.  
  112. ; data
  113. deg     dw 180             ; dumb example - everyone knows this is pi radians
  114.  
  115. ; code
  116.         .
  117.         .
  118.         .
  119.         fild   deg         ; load degrees into ST(0)
  120.         call   deg2rad     ; it comes back with ST(0) = radians
  121.  
  122.  
  123.  
  124. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  125.  
  126. F2C:        convert degrees Fahrenheit to degrees Celcius
  127. Source:     f2c.asm
  128.  
  129. 80x87 required
  130.  
  131. Call with:  ST(0) = degrees Fahrenheit
  132. Returns:    ST(0) = degrees Celcius
  133. Uses:       ST(0), 80x87 flags
  134. Example:
  135.  
  136. include code32.inc
  137.  
  138. extrn   f2c:near
  139.  
  140. ; data
  141. f0      dw 212           ; 212 degrees Farenheit
  142. c0      dw ?             ; going to store degrees Celcius here
  143.  
  144. ; code
  145.         .
  146.         .
  147.         .
  148.         fild   f0        ; load degrees Fahrenheit into ST(0)
  149.         call   f2c       ; returns degrees Celcius in ST(0)
  150.         fistp  c0        ; save degrees Celcius and pop the 8087's stack
  151.  
  152.  
  153.  
  154. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  155.  
  156. FACTORIAL:  calculates the factorial of an integer
  157. Source:     factori.asm
  158.  
  159. 80x87 required
  160.  
  161. Call with:  EAX = signed integer value
  162. Returns:    ST(0) = factorial of the integer value
  163.             Note: factorials get very large with relatively small integers
  164. Uses:       ST(0); coprocessor stack is pushed, ST(7) is lost
  165. Example:
  166.  
  167. include code32.inc
  168.  
  169. extrn   factorial:near
  170.  
  171. ; code
  172.         .
  173.         .
  174.         .
  175.         mov   eax,6          ; gonna calculate the factorial of 6
  176.         call  factorial
  177.  
  178.  
  179.  
  180. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  181.  
  182. FPRIMEI2:   calculate the derivative of a polynomial function
  183. Source:     fprimei2.asm
  184.  
  185. 80x87 NOT required
  186.  
  187. Call with:  ESI pointing to equation coefficients; all coefficients
  188.                must be 2-byte signed integers
  189.             ECX = order of polynomial (i. e., a quadratic function
  190.                is a second-order polynomial, so ECX = 2)
  191.                ECX limited to 0 < ECX < 32768
  192. Returns:    nothing
  193. Uses:       nothing
  194. Example:
  195.  
  196. include code32.inc
  197.  
  198. extrn   fprimei2:near
  199.  
  200. ; data
  201.  
  202. fx      dw 2,0,3,2,0,5      ; the function y = 2+3*(x^2)+2*(x^3)+5*(x^5)
  203.  
  204. ; code
  205.         .
  206.         .
  207.         .
  208.         mov     ecx,5        ; fifth order polynomial
  209.         lea     esi,fx       ; point to f(x) coefficients (2-byte integers)
  210.         call    fprimei2     ; calculate derivative of the function
  211.                              ; results:
  212.                              ; fx=0, fx+2=6, fx+4=6, fx+6=0, fx+8=25, fx+10=0
  213.  
  214.  
  215. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  216.  
  217. FPRIMEI4:   calculate the derivative of a polynomial function
  218. Source:     fprimei4.asm
  219.  
  220. 80x87 NOT required
  221.  
  222. Call with:  ESI pointing to equation coefficients; all coefficients
  223.                must be 4-byte signed integers
  224.             ECX = order of polynomial (i. e., a quadratic function
  225.                is a second-order polynomial, so ECX = 2)
  226.                ECX limited to 0 < ECX < 32768
  227. Returns:    nothing
  228. Uses:       nothing
  229. Example:
  230.  
  231. include code32.inc
  232.  
  233. extrn   fprimei4:near
  234.  
  235. ; data
  236.  
  237. fx      dd 2,0,3,2,0,5      ; the function y = 2+3*(x^2)+2*(x^3)+5*(x^5)
  238.  
  239. ; code
  240.         .
  241.         .
  242.         .
  243.         mov     ecx,5        ; fifth order polynomial
  244.         lea     esi,fx       ; point to f(x) coefficients (2-byte integers)
  245.         call    fprimei4     ; calculate derivative of the function
  246.                              ; results:
  247.                              ; fx=0, fx+2=6, fx+4=6, fx+6=0, fx+8=25, fx+10=0
  248.  
  249.  
  250. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  251.  
  252. FPRIMEF4:   calculate the derivative of a polynomial function
  253. Source:     fprimef4.asm
  254.  
  255. 80x87 required
  256.  
  257. Call with:  ESI pointing to equation coefficients; all coefficients
  258.                must be float4 values
  259.             ECX = order of polynomial (i. e., a quadratic function
  260.                is a second-order polynomial, so ECX = 2)
  261.                0 < ECX < 32768
  262.  
  263. Returns:    nothing
  264. Uses:       nothing
  265. Example:
  266.  
  267. include code32.inc
  268.  
  269. extrn   fprimef4:near
  270.  
  271. ; data
  272.  
  273. fx      dd 2.2,0.0,3.5,2.0,0.0,5.1
  274.                             ; the function y = 2.2+3.5*(x^2)+2*(x^3)+5.1*(x^5)
  275.  
  276. ; code
  277.         .
  278.         .
  279.         .
  280.         mov     ecx,5        ; fifth order polynomial
  281.         lea     esi,fx       ; point to f(x) coefficients (float4 values)
  282.         call    fprimef4     ; calculate derivative of the function
  283.  
  284.  
  285. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  286.  
  287. FPRIMEF8:   calculate the derivative of a polynomial function
  288. Source:     fprimef8.asm
  289.  
  290. 80x87 required
  291.  
  292. Call with:  ESI pointing to equation coefficients; all coefficients
  293.                must be float8 values
  294.             ECX = order of polynomial (i. e., a quadratic function
  295.                is a second-order polynomial, so ECX = 2)
  296.                0 < ECX < 32768
  297.  
  298. Returns:    nothing
  299. Uses:       nothing
  300. Example:
  301.  
  302. include code32.inc
  303.  
  304. extrn   fprimef8:near
  305.  
  306. ; data
  307.  
  308. fx      dq 2.2,0.0,3.5,2.0,0.0,5.1
  309.                             ; the function y = 2.2+3.5*(x^2)+2*(x^3)+5.1*(x^5)
  310.  
  311. ; code
  312.         .
  313.         .
  314.         .
  315.         mov     ecx,5        ; fifth order polynomial
  316.         lea     esi,fx       ; point to f(x) coefficients (float4 values)
  317.         call    fprimef8     ; calculate derivative of the function
  318.  
  319.  
  320. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  321.  
  322. FVALUE:     calculate the future value of a given present value and
  323.             equal periodic payments
  324. Source:     fvalue.asm (xtothey.asm)
  325.  
  326. 80x87 required
  327.  
  328. Call with:  DS:[SI] pointing to an ASM32 Financial data structure
  329.             (see FINDATA.INC).  The pv, n, i, and pmt data must be
  330.             current before calling fvalue.
  331. Returns:    updates fv in FINDATA data structure; future value also
  332.             returned in ST(0)
  333. Uses:       80x87 stack
  334. Evample:
  335.  
  336. include  asm.inc
  337. include  findata.inc
  338.  
  339. extrn    fvalue:near
  340.  
  341. .data
  342.  
  343. case1    findata <12,.0525,100.0,10.0,> ; n = 12 periods
  344.                                         ; i = .0525 (5.25% interest rate per n)
  345.                                         ; present value = 100
  346.                                         ; 10 = payment per n period
  347.  
  348. .code
  349. ; program fragment assumes DS:@data
  350.          .
  351.          .
  352.          .
  353.          lea  si,case1
  354.          call fvalue                    ; calculate future value; update
  355.                                         ; fv in case1
  356.  
  357. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  358.  
  359. LINEFITF4:  fit a line equation to a series of float4 data points
  360. LINEFITF8:  fit a line equation to a series of float8 data points
  361. LINEFITI2:  fit a line equation to a series of i2 data points
  362. LINEFITI4:  fit a line equation to a series of i4 data points
  363. Source:     linefit.asm
  364.  
  365. 80x87 required
  366.  
  367.             LineFit subroutines use the Least Squares method to calculate
  368.             the a and b coefficients of the equation
  369.  
  370.             y = a + bx
  371.  
  372.             which best fits the given data points.  See also CubeFit
  373.             and QuadFit.
  374.             The data series at DS:[BX] consists of n sets of x and y
  375.             coordinates.
  376.  
  377. Call with:  EBX pointing to data series
  378.             ECX = number of (x,y) points
  379. Returns:    ST(0) = a
  380.             ST(1) = b
  381.             ST(2) = Σx
  382.             ST(3) = Σxx
  383.             ST(4) = Σy
  384.             ST(5) = Σxy
  385. Uses:       entire 80x87 stack
  386. Example:
  387.  
  388. include code32.inc
  389.  
  390. extrn   linefiti2:near
  391.  
  392. ; data
  393. points  dw 1,5           ; first (x,y) coordinate pair
  394.         dw 3,12          ; x1 = 3, y1 = 12
  395.         dw 7,24          ; x2 = 7, y2 = 24
  396.         dw 5,17          ; x3 = 5, y3 = 17
  397.         dw 10,33         ; x4 = 10, y4 = 33
  398. n equ ($-points) shr 2   ; number of coordinate pairs (5 in this case)
  399.  
  400. ; code
  401.         .
  402.         .
  403.         .
  404.         lea   ebx,points  ; point to data series
  405.         mov   ecx,n       ; 5 data points
  406.         call  linefiti2   ; returns a in ST(0) and b in ST(1)
  407.  
  408.  
  409.  
  410. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  411.  
  412. NORMF4, NORMF4b:   normalize a float4 array
  413. Source:            normf4.asm (maxf4.asm)
  414.  
  415. NORMF8, NORMF8b:   normalize a float8 array
  416. Source:            normf8.asm (maxf8.asm)
  417.  
  418. 80x87 required
  419.  
  420. Call with:  EDI pointing to the numeric array
  421.             ECX = number of values in the array
  422.             ST(0) = number to normalize the array to
  423.             normf?b: EBX = bytes between data points
  424.             normf4 assumes EBX = 4, norm f8 assumes EBX = 8
  425.  
  426.             NormF4 and NormF8 assume that the maximum value of the data
  427.             is greater than zero.  I have used these subroutines
  428.             to scale data upward or downward, for example, to convert
  429.             from raw data to percent-of-maximum data.
  430.  
  431. Returns:    ST(0) = scaling factor
  432. Uses:       ST(0); ST(7) and ST(6) are pushed off the coprocessor stack
  433. Example:
  434.  
  435. include code32.inc
  436.  
  437. extrn   normf4:near
  438.  
  439. ; data
  440.  
  441. hundred dw 100            ; convert all data to percent-of-peak
  442.  
  443. ; code
  444.         .
  445.         .
  446.         .
  447.         esi    edi,f4fdata   ; EDI points to the data
  448.         mov    ecx,1488      ; half-hourly data for a month
  449.         fild   hundred       ; make the maximum value 100
  450.         call   normf4        ; normalize the data
  451.  
  452.  
  453.  
  454. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  455.  
  456. NPVALUE:    calculate net present value of an uneven cash flow
  457. Source:     npvalue.asm (xtothey.asm)
  458.  
  459. 80x87 required
  460.  
  461. Call with:  ESI pointing to ASM32's FINDATA data structure
  462.             EBX pointing to float4 cash flow data
  463.             n, i, and fv in FINDATA must be current before calling NPValue,
  464.             and there must be at least n cash flows
  465. Returns:    updates pv in FINDATA
  466.             ST(0) = present value
  467. Uses:       80x87 stack
  468. Example:
  469.  
  470. include   code32.inc
  471. include   findata.inc
  472.  
  473. extrn     npvalue:near
  474.  
  475. ; data
  476. case1     findata <30,.105,,,0.0>     ; 30 payments, 10.5% interest, fv = 0.0
  477. payments  dd 10 dup (80.0)            ; need 30 payments for this example
  478.           dd 10 dup (95.0)
  479.           dd 10 dup (103.0)
  480.  
  481. ; code
  482.           .
  483.           .
  484.           .
  485.           lea    ebx,payments
  486.           lea    esi,case1
  487.           call   npvalue
  488.  
  489.  
  490.  
  491. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  492.  
  493. PAYMENT:    calculates periodic payment
  494. Source:     payment.asm
  495.  
  496. 80x87 required
  497.  
  498. Call with:  ESI pointing to ASM32's FINDATA data structure
  499.             n, i, fv and pv in FINDATA must be current before calling
  500.             Payment.  Payment replaces pmt in the data structure.
  501. Returns:    replaces pmt in data structure
  502. Uses:       80x87 stack; 80x86 registers and flags are unchanged
  503. Example:
  504.  
  505. include   code32.inc
  506. include   findata.inc
  507.  
  508. extrn     payment:near
  509.  
  510. ; data
  511. ; 30 payments, 10.5% interest, pv = 10,000, fv = 0.0
  512.  
  513. case1     findata <30,.105,10000.0,,0.0>
  514.  
  515. ; code
  516.           .
  517.           .
  518.           .
  519.           lea    esi,case1
  520.           call   payment
  521.  
  522.  
  523.  
  524. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  525.  
  526. PSOLVEF4:   solve a polynomial equation for y, given x; float4 equation
  527.             coefficients
  528. Source:     psolvef4.asm
  529.  
  530. PSOLVEF8:   solve a polynomial equation for y, given x; float8 equation
  531.             coefficients
  532. Source:     psolvef8.asm
  533.  
  534. PSOLVEI2:   solve a polynomial equation for y, given x; 2-byte integer
  535.             equation coefficients
  536. Source:     psolvei2.asm
  537.  
  538. PSOLVEI4:   solve a polynomial equation for y, given x; 4-byte integer
  539.             equation coefficients
  540. Source:     psolvei4.asm
  541.  
  542. 80x87 required for all psolve subroutines
  543.  
  544. Call with:  ESI pointing to equation coefficients
  545.             ECX = n (order of the equation, i. e., a quadratic equation
  546.                is a second-order polynomial, so ECX = 2)
  547.             ST(0) = x value
  548. Returns:    ST(0) = y value
  549. Uses:       most coprocessor registers
  550. Example:
  551.  
  552. include code32.inc
  553.  
  554. ; I want to calculate y for the equation
  555. ; y = 12 + 2x + 17(x**2) + 4(x**3)
  556.  
  557. extrn   psolvei2:near
  558.  
  559. ; data
  560. fx      dw 12,2,17,4
  561. n       equ 3              ; third-order equation
  562. x       dd 0.85
  563.  
  564. ; code
  565.         .
  566.         .
  567.         .
  568.         lea     esi,fx      ; DS:[SI] points to equation coefficients
  569.         mov     ecx,n       ; a third-order polynomial
  570.         fld     x           ; find y given x
  571.         call    psolvei2    ; returns y in register ST(0)
  572.  
  573.  
  574.  
  575. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  576.  
  577. PVALUE:     calculate the present value of an even cash flow
  578. Source:     pvalue.asm (xtothey.asm)
  579.  
  580. 80x87 required
  581.  
  582. Call with:  ESI] pointing to FINDATA data structure
  583.             n, i, pmt and fv must be updated before calling
  584.             pvalue.
  585. Returns:    updates pv in FINDATA data structure
  586.             ST(0) = present value
  587. Uses:       80x87 stack
  588. Example:
  589.  
  590. include  code32.inc
  591. include  findata.inc
  592.  
  593. extrn    pvalue:near
  594.  
  595. ; data
  596.  
  597. case1    findata <12,.0525,,10.0,0.0>   ; n = 12 periods
  598.                                         ; i = .0525 (5.25% interest rate per n)
  599.                                         ; present value unknown
  600.                                         ; payment per n period = 10
  601.                                         ; future value = 0
  602.  
  603. ; code
  604.          .
  605.          .
  606.          .
  607.          lea  esi,case1
  608.          call pvalue                    ; calculate present value; update
  609.                                         ; pv in case1
  610.  
  611.  
  612. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  613.  
  614. QUADFITF4:  fit a quadratic equation to a series of float4 data points
  615. QUADFITF8:  fit a quadratic equation to a series of float8 data points
  616. QUADFITI2:  fit a quadratic equation to a series of i2 data points
  617. QUADFITI4:  fit a quadratic equation to a series of i4 data points
  618. Source:     quadfit.asm
  619.  
  620. 80x87 required
  621.  
  622.             QuadFit subroutines use the Least Squares method to calculate
  623.             the a, b and c coefficients of the equation
  624.  
  625.             y = a + bx + c(x^2)
  626.  
  627.             which best fits the given data points.  See also CubeFit and
  628.             LineFit.
  629.             The data series at DS:[BX] consists of n sets of x and y
  630.             coordinates.
  631.  
  632. Call with:  EBX pointing to data series
  633.             ECX = number of (x,y) points
  634. Returns:    ST(0) = a
  635.             ST(1) = b
  636.             ST(2) = c
  637. Uses:       entire 80x87 stack
  638. Example:
  639.  
  640. include code32.inc
  641.  
  642. extrn   quadfiti2:near
  643.  
  644. ; data
  645. points  dw 1,6           ; first (x,y) coordinate pair: x0 = 1, y0 = 6
  646.         dw 2,17          ; x1 = 2, y1 = 17
  647.         dw 5,86          ; x2 = 5, y2 = 86
  648.         dw 4,57          ; x3 = 4, y3 = 57
  649.         dw 3,34          ; x4 = 3, y4 = 34
  650. n equ ($-points) shr 2   ; number of coordinate pairs (5 in this case)
  651.  
  652. ; code
  653.         .
  654.         .
  655.         .
  656.         lea   ebx,points  ; point to data series
  657.         mov   ecx,n       ; 5 data points
  658.         call  quadfiti2   ; returns a in ST(0), b in ST(1) and c in ST(2)
  659.  
  660.  
  661.  
  662. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  663.  
  664. RAD2DEG:    convert radians to degrees of arc
  665. Source:     rad2deg.asm
  666.  
  667. 80x87 required
  668.  
  669. Call with:  ST(0) = radians
  670. Returns:    ST(0) = degrees of arc
  671. Uses:       80x87 stack - ST(6) and ST(7) are lost
  672. Example:
  673.  
  674. include code32.inc
  675. extrn   rad2deg:near
  676.  
  677. ; data
  678. rad     dd 3.14159        ; dumb example - everyone knows this is 180 degrees
  679.  
  680. ; code
  681.         .
  682.         .
  683.         .
  684.         fld    rad         ; load radians into ST(0)
  685.         call   rad2deg     ; it comes back with ST(0) = degrees
  686.  
  687.  
  688.  
  689. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  690.  
  691. SAMP2POP:   convert sample standard deviation to population standard
  692.             deviation; used with StdDev subroutines.
  693. Source:     samp2pop.asm
  694.  
  695. 80x87 required
  696.  
  697. Call with:  ST(0) = sample standard deviation
  698.             ECX = n (number of data points)
  699. Returns:    ST(0) = population standard deviation
  700. Uses:       ST(0); ST(7), ST(6) and ST(5) are lost
  701. Example:    see StdDev series subroutines
  702.  
  703.  
  704. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  705.  
  706. STDDEVF4:   calculate standard deviation of a float4 data series 
  707. STDDEVF8:   calculate standard deviation of a float8 data series 
  708. STDDEVI2:   calculate standard deviation of an i2 data series 
  709. STDDEVI4:   calculate standard deviation of an i4 data series 
  710. Source:     stddev.asm
  711.  
  712. 80x87 required
  713.  
  714. Call with:  EDI pointing to data series
  715.             ECX = number of values
  716.             Note that integer values are signed integers
  717. Returns:    if CF = 1, was called with ECX = 0
  718.             if CF = 0, ST(0) = standard deviation
  719.             The value returned by StdDev subroutines is the sample standard
  720.             deviation S; population standard deviation SP is calculated from
  721.             sample standard deviation with this formula:
  722.  
  723.             SP = S * SQRT((n - 1) / n)
  724.  
  725. Uses:       CF, coprocessor registers
  726. Example:
  727.  
  728. include code32.inc
  729.  
  730. extrn   stddevf4:near       ; my data series is in float4 format
  731. extrn   samp2pop:near       ; I want the result as a
  732.                             ; population standard deviation
  733. ; code
  734.         .
  735.         .
  736.         .
  737. ; the program has established a series of float4 values, and I need the
  738. ; standard deviation of the series
  739.         lea   edi,series_of_numbers
  740.         mov   dcx,1600       ; a whole bunch of data
  741.         call  stddevf4       ; ST(0) = sample standard deviation
  742.  
  743. ; the standard deviation returned by StdDev subroutines is the sample
  744. ; standard deviation.  Use samp2pop to convert to population standard
  745. ; deviation
  746.         call  samp2pop       ; ST(0) = population standard deviation
  747.  
  748. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  749.  
  750. XTOTHEY:    calculates x to the y power (x^y)
  751. Source:     xtothey.asm
  752.  
  753. 80x87 required
  754.  
  755. Call with:  ST(0) = x, ST(1) = y
  756. Returns:    ST(0) = x^y, coprocessor stack popped
  757. Uses:       coprocessor stack
  758. Example:
  759.  
  760. include code32.inc
  761.  
  762. extrn   xtothey:near
  763.  
  764. ; data
  765.  
  766. x       dd 17.4
  767. y       dd .3
  768.  
  769. ; code
  770.         .
  771.         .
  772.         .
  773.         fld    y                ; ST(0) = exponent
  774.         fld    x                ; ST(0) = x, ST(1) = exponent
  775.         call   xtothey          ; calculate x**y
  776.  
  777.