ReactOS 0.4.16-dev-927-g467dec4
imaxdiv.cpp
Go to the documentation of this file.
1//
2// imaxdiv.cpp
3//
4// Copyright (c) Microsoft Corporation. All rights reserved.
5//
6// Defines imaxdiv(), which performs a signed divide using intmax_t operands
7// and returns the quotient and remainder. No validation of the arguments is
8// done.
9//
10#include <inttypes.h>
11
12
13
14extern "C" imaxdiv_t __cdecl imaxdiv(intmax_t const numerator, intmax_t const denominator)
15{
17
18 result.quot = numerator / denominator;
19 result.rem = numerator - denominator * result.quot;
20
21 // Fix incorrect truncation:
22 #pragma warning(push)
23 #pragma warning(disable: 4127)
24 static bool const fix_required = (-1 / 2) < 0;
25 if (fix_required && result.quot < 0 && result.rem != 0)
26 {
27 result.quot += 1;
28 result.rem -= denominator;
29 }
30 #pragma warning(pop)
31
32 return result;
33}
34
35
36
37/*
38 * Copyright (c) 1992-2010 by P.J. Plauger. ALL RIGHTS RESERVED.
39 * Consult your license regarding permissions and restrictions.
40V5.30:0009 */
#define __cdecl
Definition: accygwin.h:79
GLuint64EXT * result
Definition: glext.h:11304
imaxdiv_t __cdecl imaxdiv(intmax_t const numerator, intmax_t const denominator)
Definition: imaxdiv.cpp:14
__MINGW_EXTENSION typedef long long intmax_t
Definition: stdint.h:68