home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 1.ddi / MATHSRC.ZIP / CEIL.CAS < prev    next >
Encoding:
Text File  |  1992-06-10  |  1.3 KB  |  56 lines

  1. /*------------------------------------------------------------------------
  2.  * filename - ceil.cas
  3.  *
  4.  * function(s)
  5.  *        ceil - rounds up
  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.  
  23.  
  24. /*--------------------------------------------------------------------------*
  25.  
  26. Name            ceil - rounds up
  27.  
  28. Usage           double ceil(double x);
  29.  
  30. Prototype in    math.h
  31.  
  32. Description     ceil finds the smallest integer not less than x.
  33.  
  34. Return value    ceil returns the integer found as a double.
  35.  
  36. *---------------------------------------------------------------------------*/
  37. #pragma warn -rvl
  38.  
  39. double _FARFUNC ceil( double x )
  40. {
  41. asm     FLD     DOUBLE (x)
  42.  
  43. asm     mov     ax, x [6]
  44. asm     shl     ax, 1
  45. asm     cmp     ax, 7FE0h + 06A0h       /* 2^53, maximum double precision */
  46. asm     ja      dlm_beyond
  47.  
  48. asm     mov     ch, 08          /* iNDP-87 control bits for ceiling mode */
  49.         __round();
  50.  
  51. dlm_beyond:                     /* magnitudes beyond 2^53 have no fraction */
  52. dlm_end:
  53.         return;
  54. }
  55. #pragma warn .rvl
  56.