home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 2.ddi / MATH.ZIP / LDEXP.CAS < prev    next >
Encoding:
Text File  |  1990-06-07  |  2.3 KB  |  95 lines

  1. /*------------------------------------------------------------------------
  2.  * filename - ldexp.cas
  3.  *
  4.  * function(s)
  5.  *        ldexp - calculates value * 2^exp
  6.  *-----------------------------------------------------------------------*/
  7.  
  8. /*[]------------------------------------------------------------[]*/
  9. /*|                                                              |*/
  10. /*|     Turbo C Run Time Library - Version 3.0                   |*/
  11. /*|                                                              |*/
  12. /*|                                                              |*/
  13. /*|     Copyright (c) 1987, 1990 by Borland International        |*/
  14. /*|     All Rights Reserved.                                     |*/
  15. /*|                                                              |*/
  16. /*[]------------------------------------------------------------[]*/
  17.  
  18.  
  19. #pragma inline
  20. #include <asmrules.h>
  21.  
  22. #include <_math.h>
  23. #include <math.h>
  24. #include <errno.h>
  25.  
  26. /*--------------------------------------------------------------------------*
  27.  
  28. Name        ldexp - calculates value * 2^exp
  29.  
  30. Usage        double ldexp(double value, int exp);
  31.  
  32. Prototype in    math.h
  33.  
  34. Description    ldexp calculates value * 2^exp
  35.  
  36. Return value    ldexp returns value * 2^exp
  37.         Overflows return HUGE_VAL * sign(value), underflows return 0.0,
  38.         in both cases with errno set to ERANGE.
  39.  
  40. *---------------------------------------------------------------------------*/
  41. #pragma warn -rvl
  42. double    ldexp (double value, int scale)
  43. {
  44.     double    yVal;            /* used in error exits */
  45.  
  46. asm    FILD    W0 (scale)
  47. /*
  48.   While that is loading, we should check for range error.
  49. */
  50. asm    mov    ax, 7FF0h
  51. asm    and    ax, value [6]
  52. asm    mov    cl, 4
  53. asm    ror    ax, cl
  54.  
  55. asm    FLD    DOUBLE (value)
  56. asm    jz    ldx_zero
  57.  
  58. asm    mov    bx, scale
  59. asm    cmp    bh, 7h
  60. asm    jg    ldx_overflow
  61. asm    cmp    bh, -7h
  62. asm    jl    ldx_overflow
  63.  
  64. asm    add    ax, bx
  65. asm    jng    ldx_underflow
  66. asm    cmp    ax, 7FFh
  67. asm    jnl    ldx_overflow
  68.  
  69. asm    FSCALE
  70. ldx_zero:
  71. asm    FSTP    st(1)            /* remove the scale from the stack */
  72.  
  73. ldx_end:
  74.     return;
  75.  
  76.  
  77. ldx_overflow:
  78. asm    mov    si, OVERFLOW
  79. asm    jmp    short    ldx_err
  80.  
  81.  
  82. ldx_underflow:
  83. asm    mov    si, UNDERFLOW
  84.  
  85. ldx_err:
  86. asm    FSTP    st(0)            /* pop value from stack */
  87. asm    FSTP    DOUBLE (yVal)        /* yVal = scale        */
  88.  
  89. #pragma    warn -ret
  90.     return    _matherr (_SI, "ldexp", &value, &yVal,
  91.         (OVERFLOW == _SI) ? HUGE_VAL : 0.0);
  92. #pragma    warn .ret
  93. }
  94. #pragma warn .rvl
  95.