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

  1. /*------------------------------------------------------------------------
  2.  * filename - ldexpl.cas
  3.  *
  4.  * function(s)
  5.  *        ldexpl - calculates value * 2^exp (long double version)
  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            ldexpl - calculates value * 2^exp
  27.  
  28. Usage           long double ldexpl(long double value, int exp);
  29.  
  30. Prototype in    math.h
  31.  
  32. Description     ldexpl calculates value * 2^exp
  33.  
  34. Return value    ldexpl 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. long double _FARFUNC ldexpl (long double value, int scale)
  41. {
  42.         long 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, 7FFFh
  49. asm     and     ax, value [8]
  50.  
  51. asm     FLD     LONGDOUBLE (value)
  52. asm     jz      ldx_zero
  53.  
  54. asm     add     ax, scale
  55. asm     jo      ldx_overflow            /* exponent too large */
  56. asm     jle     ldx_underflow           /* exponent zero or negative */
  57. asm     cmp     ax,7FFFH                /* exponent is INF */
  58. asm     je      ldx_overflow
  59.  
  60. asm     FSCALE
  61. ldx_zero:
  62. asm     FSTP    st(1)                   /* remove the scale from the stack */
  63.  
  64. ldx_end:
  65.         return;
  66.  
  67.  
  68. ldx_overflow:
  69. asm     mov     si, OVERFLOW
  70. asm     jmp     short   ldx_err
  71.  
  72.  
  73. ldx_underflow:
  74. asm     mov     si, UNDERFLOW
  75.  
  76. ldx_err:
  77. asm     FSTP    st(0)                   /* pop value from stack */
  78. asm     FSTP    LONGDOUBLE (yVal)       /* yVal = scale         */
  79.  
  80. #pragma warn -ret
  81.         return  __matherrl (_SI, "ldexpl", &value, &yVal,
  82.                 (OVERFLOW == _SI) ? _LHUGE_VAL : 0.0);
  83. #pragma warn .ret
  84. }
  85. #pragma warn .rvl
  86.