home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 5.ddi / CLIBSRC2.ZIP / CPLX1.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  2.0 KB  |  100 lines

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