home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / gnuc / stdlib / rcs / ldiv.c,v < prev    next >
Encoding:
Text File  |  1992-07-04  |  1.8 KB  |  82 lines

  1. head    1.1;
  2. access;
  3. symbols
  4.     version39-41:1.1;
  5. locks;
  6. comment    @ * @;
  7.  
  8.  
  9. 1.1
  10. date    92.06.08.17.01.06;    author mwild;    state Exp;
  11. branches;
  12. next    ;
  13.  
  14.  
  15. desc
  16. @initial checkin
  17. @
  18.  
  19.  
  20. 1.1
  21. log
  22. @Initial revision
  23. @
  24. text
  25. @/*
  26.  * Copyright (c) 1990 Regents of the University of California.
  27.  * All rights reserved.
  28.  *
  29.  * This code is derived from software contributed to Berkeley by
  30.  * Chris Torek.
  31.  *
  32.  * Redistribution and use in source and binary forms are permitted
  33.  * provided that: (1) source distributions retain this entire copyright
  34.  * notice and comment, and (2) distributions including binaries display
  35.  * the following acknowledgement:  ``This product includes software
  36.  * developed by the University of California, Berkeley and its contributors''
  37.  * in the documentation or other materials provided with the distribution
  38.  * and in all advertising materials mentioning features or use of this
  39.  * software. Neither the name of the University nor the names of its
  40.  * contributors may be used to endorse or promote products derived
  41.  * from this software without specific prior written permission.
  42.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  43.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  44.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  45.  */
  46.  
  47. #if defined(LIBC_SCCS) && !defined(lint)
  48. static char sccsid[] = "@@(#)ldiv.c    5.1 (Berkeley) 5/16/90";
  49. #endif /* LIBC_SCCS and not lint */
  50.  
  51. #define KERNEL
  52. #include "ixemul.h"
  53.  
  54. #include <stdlib.h>        /* ldiv_t */
  55.  
  56. /*
  57.  * I AM NOT SURE THIS IS COMPLETELY PORTABLE
  58.  * (or that it is even right)
  59.  */
  60. ldiv_t const
  61. ldiv(long num, long denom)
  62. {
  63.     ldiv_t r;
  64.  
  65.     /* see div.c for comments */
  66.  
  67.     if (num > 0 && denom < 0) {
  68.         num = -num;
  69.         denom = -denom;
  70.     }
  71.     r.quot = num / denom;
  72.     r.rem = num % denom;
  73.     if (num < 0 && denom > 0) {
  74.         if (r.rem > 0) {
  75.             r.quot++;
  76.             r.rem -= denom;
  77.         }
  78.     }
  79.     return (r);
  80. }
  81. @
  82.