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

  1. /*------------------------------------------------------------------------
  2.  * filename - ldexp.cas
  3.  *
  4.  * function(s)
  5.  *        ldexp - calculates value * 2^exp
  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            ldexp - calculates value * 2^exp
  27.  
  28. Usage           double ldexp(double value, int exp);
  29.  
  30. Prototype in    math.h
  31.  
  32. Description     ldexp calculates value * 2^exp
  33.  
  34. Return value    ldexp returns value * 2^exp
  35.                 Overflows return HUGE_VAL * sign(value), underflows return 0.0,
  36.                 in both cases with errno set to ERANGE.
  37.  
  38. *---------------------------------------------------------------------------*/
  39. #pragma warn -rvl
  40. double  _FARFUNC ldexp (double value, int scale)
  41. {
  42.         double  yVal;               /* used in error exits */
  43.  
  44. asm     FILD    W0 (scale)
  45. /*
  46.   While that is loading, we should check for range error.
  47. */
  48. asm     mov     ax, 7FF0h
  49. asm     and     ax, value [6]
  50. asm     mov     cl, 4
  51. asm     ror     ax, cl
  52.  
  53. asm     FLD     DOUBLE (value)
  54. asm     jz      ldx_zero
  55.  
  56. asm     mov     bx, scale
  57. asm     cmp     bh, 7h
  58. asm     jg      ldx_overflow
  59. asm     cmp     bh, -7h
  60. asm     jl      ldx_overflow
  61.  
  62. asm     add     ax, bx
  63. asm     jng     ldx_underflow
  64. asm     cmp     ax, 7FFh
  65. asm     jnl     ldx_overflow
  66.  
  67. asm     FSCALE
  68. ldx_zero:
  69. asm     FSTP    st(1)                   /* remove the scale from the stack */
  70.  
  71. ldx_end:
  72.         return;
  73.  
  74.  
  75. ldx_overflow:
  76. asm     mov     si, OVERFLOW
  77. asm     jmp     short   ldx_err
  78.  
  79.  
  80. ldx_underflow:
  81. asm     mov     si, UNDERFLOW
  82.  
  83. ldx_err:
  84. asm     FSTP    st(0)                   /* pop value from stack */
  85. asm     FSTP    DOUBLE (yVal)           /* yVal = scale         */
  86.  
  87. #pragma warn -ret
  88.         return  _matherr (_SI, "ldexp", &value, &yVal,
  89.                 (OVERFLOW == _SI) ? HUGE_VAL : 0.0);
  90. #pragma warn .ret
  91. }
  92. #pragma warn .rvl
  93.