home *** CD-ROM | disk | FTP | other *** search
- /*------------------------------------------------------------------------
- * filename - ceil.cas
- *
- * function(s)
- * ceil - rounds up
- *-----------------------------------------------------------------------*/
-
- /*[]------------------------------------------------------------[]*/
- /*| |*/
- /*| Turbo C Run Time Library - Version 3.0 |*/
- /*| |*/
- /*| |*/
- /*| Copyright (c) 1987, 1990 by Borland International |*/
- /*| All Rights Reserved. |*/
- /*| |*/
- /*[]------------------------------------------------------------[]*/
-
-
- #pragma inline
- #include <asmrules.h>
-
- #include <_math.h>
- #include <math.h>
-
-
- /*--------------------------------------------------------------------------*
-
- Name ceil - rounds up
-
- Usage double ceil(double x);
-
- Prototype in math.h
-
- Description ceil finds the smallest integer not less than x.
-
- Return value ceil returns the integer found as a double.
-
- *---------------------------------------------------------------------------*/
- #pragma warn -rvl
- double ceil (double x)
- {
- asm FLD DOUBLE (x)
-
- asm mov ax, x [6]
- asm shl ax, 1
- asm cmp ax, 7FE0h + 06A0h /* 2^53, maximum double precision */
- asm ja dlm_beyond
-
- asm push ax /* make a word on the stack */
- asm mov bx, sp
-
- asm FSTCW W0 (SS_ [bx]) /* read out the current control word */
- asm mov ax, 0F3FFh
- asm FWAIT
- asm and ax, SS_ [bx] /* mask out the rounding control */
- asm or ah, 08 /* iNDP-87 control bits for ceiling mode */
- asm push ax
- asm FLDCW W0 (SS_ [bx-2])
- asm pop ax
-
- asm FRNDINT /* round to integer */
-
- asm FLDCW W0 (SS_ [bx]) /* restore original rounding control */
- asm pop ax
-
- dlm_beyond: /* magnitudes beyond 2^53 have no fraction */
- dlm_end:
- return;
- }
- #pragma warn .rvl
-