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

  1. /*------------------------------------------------------------------------
  2.  * filename - ceil.cas
  3.  *
  4.  * function(s)
  5.  *        ceil - rounds up
  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.  
  25.  
  26. /*--------------------------------------------------------------------------*
  27.  
  28. Name        ceil - rounds up
  29.  
  30. Usage        double ceil(double x);
  31.  
  32. Prototype in    math.h
  33.  
  34. Description    ceil finds the smallest integer not less than x.
  35.  
  36. Return value    ceil returns the integer found as a double.
  37.  
  38. *---------------------------------------------------------------------------*/
  39. #pragma warn -rvl
  40. double    ceil (double x)
  41. {
  42. asm    FLD    DOUBLE (x)
  43.  
  44. asm    mov    ax, x [6]
  45. asm    shl    ax, 1
  46. asm    cmp    ax, 7FE0h + 06A0h    /* 2^53, maximum double precision */
  47. asm    ja    dlm_beyond
  48.  
  49. asm    push    ax            /* make a word on the stack */
  50. asm    mov    bx, sp
  51.  
  52. asm    FSTCW    W0 (SS_ [bx])        /* read out the current control word */
  53. asm    mov    ax, 0F3FFh
  54. asm    FWAIT
  55. asm    and    ax, SS_ [bx]        /* mask out the rounding control */
  56. asm    or    ah, 08        /* iNDP-87 control bits for ceiling mode */
  57. asm    push    ax
  58. asm    FLDCW    W0 (SS_ [bx-2])
  59. asm    pop    ax
  60.  
  61. asm    FRNDINT                /* round to integer */
  62.  
  63. asm    FLDCW    W0 (SS_ [bx])        /* restore original rounding control */
  64. asm    pop    ax
  65.  
  66. dlm_beyond:            /* magnitudes beyond 2^53 have no fraction */
  67. dlm_end:
  68.     return;
  69. }
  70. #pragma warn .rvl
  71.