home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 2.ddi / CLIB2.ZIP / CPLX1.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-07  |  2.2 KB  |  95 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - cplx1.cpp
  3.  * C++ Complex Library Routines
  4.  *-----------------------------------------------------------------------*/
  5.  
  6. /*[]------------------------------------------------------------[]*/
  7. /*|                                                              |*/
  8. /*|     Turbo C++ Run Time Library - Version 1.0                 |*/
  9. /*|                                                              |*/
  10. /*|                                                              |*/
  11. /*|     Copyright (c) 1990 by Borland International              |*/
  12. /*|     All Rights Reserved.                                     |*/
  13. /*|                                                              |*/
  14. /*[]------------------------------------------------------------[]*/
  15.  
  16. #pragma inline
  17.  
  18. #define RETURN_TOS    ;\
  19.     long double x_tos;        ;\
  20.     asm    fstp    tbyte ptr x_tos    ;\
  21.         return x_tos;
  22.  
  23. #include <complex.h>
  24. #include "asmrules.h"
  25.  
  26. #define REAL    qword ptr
  27. #define REAL1    dword ptr
  28. #define REAL2    qword ptr
  29. #define REAL3    tbyte ptr
  30.  
  31. #define LONG    dword ptr
  32. #define WORD    word ptr
  33. #define BYTE    byte ptr
  34.  
  35.  
  36. double _Cdecl abs(complex& z)
  37. {
  38. asm    LES_    bx, z
  39. asm    fld    REAL ES_ [bx]
  40. asm    fmul    st(0), st(0)
  41. asm    fld    REAL ES_ [bx+8]
  42. asm    fmul    st(0), st(0)
  43. asm    fadd
  44. asm    fsqrt
  45.     RETURN_TOS;
  46. }
  47.  
  48. double _Cdecl norm(complex& z)
  49. {
  50. /*
  51.     return z.re*z.re + z.im*z.im;
  52. */
  53. asm    LES_    bx, z
  54. asm    fld    REAL ES_ [bx]
  55. asm    fmul    st(0), st(0)
  56. asm    fld    REAL ES_ [bx+8]
  57. asm    fmul    st(0), st(0)
  58. asm    fadd
  59.     RETURN_TOS;
  60. }
  61.  
  62. complex& _Cdecl complex::operator*=(complex& z2)
  63. {
  64. /*
  65.     return complex(z1.re*z2.re - z1.im*z2.im, z1.im*z2.re + z1.re*z2.im);
  66. */
  67. asm    LES_    bx, z2
  68. asm    fld    REAL ES_ [bx+8]
  69. asm    fld    st(0)
  70. asm    fld    REAL ES_ [bx]
  71. asm    fld    st(0)
  72.  
  73. asm    LES_    bx, this
  74. asm    fmul    REAL ES_ [bx+8]
  75. asm    fxch    st(1)
  76. asm    fmul    REAL ES_ [bx]
  77.  
  78. asm    fxch    st(2)
  79. asm    fmul    REAL ES_ [bx]
  80. asm    fxch    st(3)
  81. asm    fmul    REAL ES_ [bx+8]
  82. asm    fsubp    st(2), st(0)
  83. asm    faddp    st(2), st(0)
  84.  
  85. asm    fstp    REAL ES_ [bx]
  86. asm    fstp    REAL ES_ [bx+8]
  87.  
  88.     return *this;
  89. }
  90.  
  91. complex _Cdecl operator*(complex& z1, complex& z2)
  92. {
  93.     return complex(z1.re*z2.re - z1.im*z2.im, z1.im*z2.re + z1.re*z2.im);
  94. }
  95.