home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 2.ddi / CLIB2.ZIP / ABS.CAS next >
Encoding:
Text File  |  1990-06-07  |  1.5 KB  |  46 lines

  1. /*------------------------------------------------------------------------
  2.  * filename - abs.cas
  3.  *
  4.  * function(s)
  5.  *        abs - absolute value
  6.  *-----------------------------------------------------------------------*/
  7.  
  8. /*[]------------------------------------------------------------[]*/
  9. /*|                                                              |*/
  10. /*|     Turbo C Run Time Library - Version 3.0                   |*/
  11. /*|                                                              |*/
  12. /*|                                                              |*/
  13. /*|     Copyright (c) 1987,1988,1990 by Borland International    |*/
  14. /*|     All Rights Reserved.                                     |*/
  15. /*|                                                              |*/
  16. /*[]------------------------------------------------------------[]*/
  17.  
  18. #pragma inline
  19. #include <stdlib.h>
  20.  
  21. #undef abs        /* abs is defined as a macro in stdlib.h */
  22.  
  23. /*------------------------------------------------------------------------*
  24.  
  25. Name        abs - absolute value
  26.  
  27. Usage        int abs(int i);
  28.  
  29. Prototype in    stdlib.h
  30.  
  31. Description    abs returns the absolute value of the integer argument i
  32.  
  33. Return value    Integer value in  the range 0 to 32767,  with the exception
  34.                 that an argument of -32768 is returned as -32768.
  35.         
  36. *--------------------------------------------------------------------------*/
  37. int abs(int i)
  38. {
  39. asm    mov    ax, i
  40. asm    or    ax, ax
  41. asm    jge    exit
  42. asm    neg    ax
  43. exit:
  44.     return _AX;
  45. }
  46.