home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 2.ddi / RTLINSRC.ZIP / _MATH.H < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  8.1 KB  |  288 lines

  1. /*------------------------------------------------------------------------
  2.  * filename - _math.h
  3.  *
  4.  *      Access to the Floating Point Support Library.
  5.  *-----------------------------------------------------------------------*/
  6.  
  7. /*[]------------------------------------------------------------[]*/
  8. /*|                                                              |*/
  9. /*|     C/C++ Run Time Library - Version 4.0                     |*/
  10. /*|                                                              |*/
  11. /*|                                                              |*/
  12. /*|     Copyright (c) 1987, 1991 by Borland International        |*/
  13. /*|     All Rights Reserved.                                     |*/
  14. /*|                                                              |*/
  15. /*[]------------------------------------------------------------[]*/
  16.  
  17. #if !defined(__MATH_H)
  18. #include <math.h>
  19. #endif
  20.  
  21. /*
  22.  * Parameters must be supplied on the iNDP stack and are consumed.
  23.  * Result will be in the iNDP TOS.
  24. */
  25.  
  26. /*
  27.  *  An iNDP_image is put into memory by the FSTENV instruction.
  28. */
  29.  
  30. typedef struct
  31. {
  32.     unsigned  control;
  33.     unsigned  status_;
  34.     unsigned  tags;
  35.     unsigned  ip;
  36.     unsigned  ip_opcode;
  37.     unsigned  dp;
  38.     unsigned  dptop;
  39. }
  40.     iNDP_env;
  41.  
  42. #if defined(__OS2__) || defined(_Windows)
  43.  
  44. #ifdef __cplusplus
  45. extern "C" {
  46. #endif
  47. void near _f87_Sine(void);
  48. void near _f87_Cosine(void);
  49. void near _f87_Tangent(void);
  50. void near _f87_ArcTan(void);
  51.  
  52. void near _f87_Log(void);
  53. void near _f87_Log2(void);
  54. void near _f87_Log10(void);
  55.  
  56. void near _f87_Exp(void);
  57. void near _f87_Exp2(void);
  58. void near _f87_Exp10(void);
  59.  
  60. #ifdef __cplusplus
  61. }
  62. #endif
  63.  
  64. #else   /* not __OS2__ or _Windows */
  65.  
  66. /*
  67. These shortcut codes are like emulated 8087 instructions, but they enter
  68. the emulator at a level which bypasses simulation of that chip's status
  69. registers.  Therefore the emulation is not strict.  Also the addressing
  70. modes are fixed, none of the '87 flexibility is available (nor do you pay
  71. the time penalty of emulating the instruction decode).  They are designed
  72. to match the sequences the compiler frequently generates.
  73.  
  74. These shortcuts MUST be called in a fixed pattern.  For most operations
  75. the sequence is:
  76. */
  77.  
  78. #define _FAST_(shortCode)  int  3Eh;  asm db    shortCode, 90h
  79.  
  80. /*
  81. A few operations require a 4-byte sequence with two trailing bytes.
  82. The second trailing byte supplies a register count or some other parameter.
  83. */
  84.  
  85. #define _FAST4_(shortCode,rNum)   int   3Eh; asm db  shortCode, rNum
  86.  
  87. #define shortcutInt     0x3E
  88.  
  89. typedef enum  _shortCodes_
  90. {
  91.         _FSCALEAX_      = 0xA2,
  92.         _FCOM_          = 0xA4,
  93.         _FSTCWAX_       = 0xA6,
  94.         _FLDSTN_        = 0xA8,         /* FAST4        */
  95.  
  96.         _FASC2BIN_      = 0xAA,
  97.         _FBIN2ASC_      = 0xAC,
  98.  
  99.         _FNINIT_        = 0xAE,
  100.         _FLDCW_         = 0xB0,
  101.         _FSTSWAX_       = 0xB2,
  102.         _FERROR_        = 0xB4,
  103.  
  104.         _FFRAC_         = 0xB6,
  105.  
  106.         _FSTPRI_        = 0xB8,
  107.         _FSTPRUI_       = 0xBA,
  108.         _FSTPRL_        = 0xBC,
  109.         _FSTPRUL_       = 0xBE,
  110.  
  111.         _FSTPTI_        = 0xC0,
  112.         _FSTPTUI_       = 0xC2,
  113.         _FSTPTL_        = 0xC4,
  114.         _FSTPTUL_       = 0xC6,
  115.  
  116.         _FLDI_          = 0xC8,
  117.         _FLDUI_         = 0xCA,
  118.         _FLDL_          = 0xCC,
  119.         _FLDUL_         = 0xCE,
  120.  
  121.         _FLDLEC_        = 0xD0,
  122.         _FLDULEC_       = 0xD2,
  123.  
  124.         _FLDSDA_        = 0xD4,
  125.         _FLDSEC_        = 0xD6,
  126.         _FSTPSDA_       = 0xD8,
  127.  
  128.         _FXCHN_         = 0xDA,         /* FAST4        */
  129.  
  130. /*  The following 8 compiler-support short-cuts are supported by the
  131.     emulator even when true emulation is used and the other short-cuts
  132.     are suppressed.
  133. */
  134.         _FSPILLN_       = 0xDC,         /* FAST4        */
  135.         _FRELOADN_      = 0xDE,         /* FAST4        */
  136.  
  137.         _FCMPPS_        = 0xE0,
  138.         _FCMPPD_        = 0xE2,
  139.         _FCMPP_         = 0xE4,
  140.         _FCMP_          = 0xE6,
  141.         _FTST_          = 0xE8,
  142.         _FXAM_          = 0xEA,
  143.  
  144. /*  The following 10 transcendental short-cuts are supported by the
  145.     emulator even when true emulation is used and the other short-cuts
  146.     are suppressed.
  147. */
  148.         _FSIN_          = 0xEC,
  149.         _FCOS_          = 0xEE,
  150.         _FTAN_          = 0xF0,
  151.         _FATAN_         = 0xF2,
  152.         _FLOG_          = 0xF4,
  153.         _FLOG2_         = 0xF6,
  154.         _FLOG10_        = 0xF8,
  155.         _FEXP_          = 0xFA,
  156.         _FEXP2_         = 0xFC,
  157.         _FEXP10_        = 0xFE,
  158.  
  159. /* negatives have no simple in-line equivalents, though some (like FXCHN)
  160.    will be patched in-line.  Positives can be inline patched by a uniform
  161.    look-up table.
  162. */
  163.         _FSADD_         = 0x00,
  164.         _FSSUB_         = 0x02,
  165.         _FSSUBR_        = 0x04,
  166.         _FSMUL_         = 0x06,
  167.         _FSDIV_         = 0x08,
  168.         _FSDIVR_        = 0x0A,
  169.         _FSSQRT_        = 0x0C,
  170.  
  171.         _FLDSES_        = 0x0E,
  172.         _FLDSCS_        = 0x10,
  173.         _FLDSSS_        = 0x12,
  174.         _FLDSDS_        = 0x14,
  175.  
  176.         _FLDDES_        = 0x16,
  177.         _FLDDCS_        = 0x18,
  178.         _FLDDSS_        = 0x1A,
  179.         _FLDDDS_        = 0x1C,
  180.  
  181.         _FLDXES_        = 0x1E,
  182.         _FLDXCS_        = 0x20,
  183.         _FLDXSS_        = 0x22,
  184.         _FLDXDS_        = 0x24,
  185.  
  186.         _FLDCES_        = 0x26,
  187.         _FLDCCS_        = 0x28,
  188.         _FLDCSS_        = 0x2A,
  189.         _FLDCDS_        = 0x2C,
  190.  
  191.         _FLDBXES_       = 0x2E,
  192.         _FLDBXCS_       = 0x30,
  193.         _FLDBXSS_       = 0x32,
  194.         _FLDBXDS_       = 0x34,
  195.  
  196.         _FSTPSES_       = 0x36,
  197.         _FSTPSCS_       = 0x38,
  198.         _FSTPSSS_       = 0x3A,
  199.         _FSTPSDS_       = 0x3C,
  200.  
  201.         _FSTPDES_       = 0x3E,
  202.         _FSTPDCS_       = 0x40,
  203.         _FSTPDSS_       = 0x42,
  204.         _FSTPDDS_       = 0x44,
  205.  
  206.         _FSTPXES_       = 0x46,
  207.         _FSTPXCS_       = 0x48,
  208.         _FSTPXSS_       = 0x4A,
  209.         _FSTPXDS_       = 0x4C,
  210.  
  211.         _FSTPCES_       = 0x4E,
  212.         _FSTPCCS_       = 0x50,
  213.         _FSTPCSS_       = 0x52,
  214.         _FSTPCDS_       = 0x54,
  215.  
  216.         _FADD_          = 0x56,
  217.         _FSUB_          = 0x58,
  218.         _FSUBR_         = 0x5A,
  219.         _FMUL_          = 0x5C,
  220.         _FDIV_          = 0x5E,
  221.         _FDIVR_         = 0x60,
  222.         _FSQRT_         = 0x62,
  223.  
  224.         _FCHS_          = 0x64,
  225.         _FABS_          = 0x66,
  226.  
  227.         _FLDST0_        = 0x68,
  228.         _FSTPST0_       = 0x6A,
  229.         _FXCH_          = 0x6C,
  230.         _FRNDINT_       = 0x6E,
  231.  
  232.         _FLDZ_          = 0x70,
  233.         _FLD1_          = 0x72,
  234.         _FPREM_         = 0x74,
  235.         _FXTRACT_       = 0x76,
  236.         _FLDPI_         = 0x78,
  237. };
  238. #endif  /* not __OS2__ */
  239.  
  240. /* The flag _8087 says whether coprocessor is in use.
  241.    It is only valid floating point is used in the program.
  242.    The values are:
  243.      0 - nocoprocessor, or ignored because of SET 87=N.
  244.      1 - 8087 or 80187, or using coprocessor because of SET 87=Y.
  245.      2 - 80287
  246.      3 - 80387
  247. */
  248.  
  249. extern int cdecl _8087;
  250.  
  251. /* some 80387 opcodes */
  252.  
  253. #define OPCODE_FSIN             0D9h, 0FEh
  254. #define OPCODE_FCOS             0D9h, 0FFh
  255. #define OPCODE_FSINCOS          0D9h, 0FBh
  256. #define OPCODE_FSTSWAX          0DFh, 0E0h
  257.  
  258. #ifdef __cplusplus
  259. extern "C" {
  260. #endif
  261.  
  262. /* helper functions and variables for math library */
  263.  
  264. void pascal near        __expld(void);
  265. void pascal near        __round(void);
  266. long double pascal near __pow10(int __p);
  267.  
  268. extern char *_mathwhy[];
  269.  
  270. #ifdef __cplusplus
  271. }
  272. #endif
  273.  
  274. #if     MSC
  275. #include "msc.h"
  276. #endif
  277.  
  278. /*  The customary matherr() exception handler for math functions is
  279.     not compatible with the x3j11 draft standard for C.  _matherr() is
  280.     provided as a compromise.
  281. */
  282.  
  283. double _Cdecl _FARFUNC _matherr(_mexcep __why, char _FAR *__fun, double _FAR *__arg1p,
  284.                        double  _FAR *__arg2p, double  __retval);
  285. long double _Cdecl _FARFUNC __matherrl(_mexcep __why, char _FAR *__fun,
  286.                         long double _FAR *__arg1p, long double  _FAR *__arg2p,
  287.                         long double  __retval);
  288.