Import div.c patch by Tri-Edge AI

Signed-off-by: Jérôme Duval <jerome.duval@gmail.com>
This commit is contained in:
Puck Meerburg 2014-12-14 16:38:42 +01:00 committed by Jérôme Duval
parent a5f30beaad
commit c038f26da8

View File

@ -1,9 +1,10 @@
/*
* Copyright 2002-2007, Haiku Inc. All rights reserved.
* Copyright 2002-2010, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Author:
* Daniel Reinhold, danielre@users.sf.net
* Tri-Edge AI, triedgeai@gmail.com
*/
@ -16,9 +17,9 @@ div(int numerator, int denominator)
div_t val;
val.quot = numerator / denominator;
val.rem = numerator - denominator * val.quot;
val.rem = numerator % denominator;
if (val.rem > 0 && val.quot < 0) {
if (numerator >= 0 && val.rem < 0) {
val.rem -= denominator;
++val.quot;
}
@ -33,9 +34,9 @@ ldiv(long numerator, long denominator)
ldiv_t val;
val.quot = numerator / denominator;
val.rem = numerator - denominator * val.quot;
val.rem = numerator % denominator;
if (val.rem > 0 && val.quot < 0) {
if (numerator >= 0 && val.rem < 0) {
val.rem -= denominator;
++val.quot;
}
@ -50,9 +51,9 @@ lldiv(long long numerator, long long denominator)
lldiv_t val;
val.quot = numerator / denominator;
val.rem = numerator - denominator * val.quot;
val.rem = numerator % denominator;
if (val.rem > 0 && val.quot < 0) {
if (numerator >= 0 && val.rem < 0) {
val.rem -= denominator;
++val.quot;
}