Windows NT 4.0 source code leak
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.3 KiB

4 years ago
  1. /***
  2. *div.c - contains the div routine
  3. *
  4. * Copyright (c) 1989-1991, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Performs a signed divide and returns quotient
  8. * and remainder.
  9. *
  10. *Revision History:
  11. * 06-02-89 PHG module created
  12. * 03-14-90 GJF Made calling type _CALLTYPE1 and added #include
  13. * <cruntime.h>. Also, fixed the copyright.
  14. * 10-04-90 GJF New-style function declarator.
  15. *
  16. *******************************************************************************/
  17. #include <cruntime.h>
  18. #include <stdlib.h>
  19. /***
  20. *div_t div(int numer, int denom) - do signed divide
  21. *
  22. *Purpose:
  23. * This routine does an divide and returns the results.
  24. * Since we don't know how the Intel 860 does division, we'd
  25. * better make sure that we have done it right.
  26. *
  27. *Entry:
  28. * int numer - Numerator passed in on stack
  29. * int denom - Denominator passed in on stack
  30. *
  31. *Exit:
  32. * returns quotient and remainder in structure
  33. *
  34. *Exceptions:
  35. * No validation is done on [denom]* thus, if [denom] is 0,
  36. * this routine will trap.
  37. *
  38. *******************************************************************************/
  39. div_t _CALLTYPE1 div (
  40. int numer,
  41. int denom
  42. )
  43. {
  44. div_t result;
  45. result.quot = numer / denom;
  46. result.rem = numer % denom;
  47. if (numer < 0 && result.rem > 0) {
  48. /* did division wrong; must fix up */
  49. ++result.quot;
  50. result.rem -= denom;
  51. }
  52. return result;
  53. }