From 29fd670a1b2045602278e6aa56b1b4e7d01af092 Mon Sep 17 00:00:00 2001 From: Salvatore Benedetto Date: Sun, 31 Aug 2008 10:40:58 +0000 Subject: [PATCH] * Updated license * Removed extraneous tabs * Implemented lldiv (#2688) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27250 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/posix/div_t.h | 7 ++++--- src/system/libroot/posix/stdlib/div.c | 25 +++++++++++++++++++++---- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/headers/posix/div_t.h b/headers/posix/div_t.h index fe479f3f49..05c58e4909 100644 --- a/headers/posix/div_t.h +++ b/headers/posix/div_t.h @@ -1,8 +1,9 @@ +/* + * Copyright 2002-2005, Haiku Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + */ #ifndef _DIV_T_H_ #define _DIV_T_H_ -/* -** Distributed under the terms of the OpenBeOS License. -*/ typedef struct { int quot; diff --git a/src/system/libroot/posix/stdlib/div.c b/src/system/libroot/posix/stdlib/div.c index a9ba10c8dd..723a31515e 100644 --- a/src/system/libroot/posix/stdlib/div.c +++ b/src/system/libroot/posix/stdlib/div.c @@ -14,10 +14,10 @@ div_t div(int numerator, int denominator) { div_t val; - + val.quot = numerator / denominator; val.rem = numerator - denominator * val.quot; - + if (val.rem > 0 && val.quot < 0) { val.rem -= denominator; ++val.quot; @@ -31,10 +31,27 @@ ldiv_t ldiv(long numerator, long denominator) { ldiv_t val; - + val.quot = numerator / denominator; val.rem = numerator - denominator * val.quot; - + + if (val.rem > 0 && val.quot < 0) { + val.rem -= denominator; + ++val.quot; + } + + return val; +} + + +lldiv_t +lldiv(long long numerator, long long denominator) +{ + lldiv_t val; + + val.quot = numerator / denominator; + val.rem = numerator - denominator * val.quot; + if (val.rem > 0 && val.quot < 0) { val.rem -= denominator; ++val.quot;