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

  1. /*------------------------------------------------------------------------
  2.  * filename - floor.cas
  3.  *
  4.  * function(s)
  5.  *        floor - rounds down
  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. Name        floor - rounds down
  28.  
  29. Usage        double floor(double x);
  30.  
  31. Prototype in    math.h
  32.  
  33. Description    floor finds the largest integer not greater than x.
  34.  
  35. Return value    floor returns the integer found as a double.
  36.  
  37. *---------------------------------------------------------------------------*/
  38. #pragma warn -rvl
  39. double    floor (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    push    ax            /* make a word on the stack */
  49. asm    mov    bx, sp
  50.  
  51. asm    FSTCW    W0 (SS_ [bx])        /* read out the current control word */
  52. asm    mov    ax, 0F3FFh
  53. asm    FWAIT
  54. asm    and    ax, SS_ [bx]        /* mask out the rounding control */
  55. asm    or    ah, 04        /* iNDP-87 control bits for floor mode */
  56. asm    push    ax
  57. asm    FLDCW    W0 (SS_ [bx-2])
  58. asm    pop    ax
  59.  
  60. asm    FRNDINT                /* round to integer */
  61.  
  62. asm    FLDCW    W0 (SS_ [bx])        /* restore original rounding control */
  63. asm    pop    ax
  64.  
  65. dlm_beyond:            /* magnitudes beyond 2^53 have no fraction */
  66. dlm_end:
  67.     return;
  68. }
  69. #pragma warn .rvl
  70.