1 /* Math functions for i387.
2 Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by John C. Bowman <bowman@ipp-garching.mpg.de>, 1995.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
27 _In_ INT iMultiplicand
,
31 INT64 i64Multiplied
, i64Result
;
33 /* Check for divide by zero */
36 /* Quick sign check and return "infinite" */
37 return ((iMultiplicand
^ iMultiplier
) < 0) ? INT_MIN
: INT_MAX
;
40 /* We want to deal with a positive divisor to simplify the logic. */
43 iMultiplicand
= -iMultiplicand
;
47 /* Do the multiplication */
48 i64Multiplied
= Int32x32To64(iMultiplicand
, iMultiplier
);
50 /* If the result is positive, we add to round, else we subtract to round. */
51 if (i64Multiplied
>= 0)
53 i64Multiplied
+= (iDivisor
/ 2);
57 i64Multiplied
-= (iDivisor
/ 2);
60 /* Now do the divide */
61 i64Result
= i64Multiplied
/ iDivisor
;
63 /* Check for positive overflow */
64 if (i64Result
> INT_MAX
)
69 /* Check for negative overflow. */
70 if (i64Result
< INT_MIN
)
75 return (INT
)i64Result
;