+++ /dev/null
-/** @file\r
- The div, ldiv, and lldiv, functions compute numer / denom and\r
- numer % denom in a single operation.\r
-\r
- The div, ldiv, and lldiv functions return a structure of type div_t, ldiv_t,\r
- and lldiv_t, respectively, comprising both the quotient and the remainder.\r
- The structures shall contain (in either order) the members quot\r
- (the quotient) and rem (the remainder), each of which has the same type as\r
- the arguments numer and denom. If either part of the result cannot be\r
- represented, the behavior is undefined.\r
-\r
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
- This program and the accompanying materials are licensed and made available under\r
- the terms and conditions of the BSD License that accompanies this distribution.\r
- The full text of the license may be found at\r
- http://opensource.org/licenses/bsd-license.php.\r
-\r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-**/\r
-#include <LibConfig.h>\r
-#include <sys/EfiCdefs.h>\r
-\r
-#include <Library/BaseLib.h>\r
-#include <stdlib.h> /* div_t, ldiv_t, lldiv_t */\r
-\r
-/* DivS64x64Remainder will write the remainder as a 64-bit value, so we store\r
- it first into bigrem and then into r.rem. This avoids writing the remainder\r
- beyond the end of the div_t structure.\r
-*/\r
-div_t\r
-div(int num, int denom)\r
-{\r
- div_t r;\r
- INT64 bigrem;\r
-\r
- r.quot = (int)DivS64x64Remainder( (INT64)num, (INT64)denom, &bigrem);\r
- r.rem = (int)bigrem;\r
-\r
- return (r);\r
-}\r
-\r
-/* DivS64x64Remainder will write the remainder as a 64-bit value, so we store\r
- it first into bigrem and then into r.rem. This avoids writing the remainder\r
- beyond the end of the div_t structure.\r
-*/\r
-ldiv_t\r
-ldiv(long num, long denom)\r
-{\r
- ldiv_t r;\r
- INT64 bigrem;\r
-\r
- r.quot = (long)DivS64x64Remainder( (INT64)num, (INT64)denom, &bigrem);\r
- r.rem = (long)bigrem;\r
-\r
- return (r);\r
-}\r
-\r
-/* DivS64x64Remainder will write the remainder as a 64-bit value, so we store\r
- it first into bigrem and then into r.rem. This avoids writing the remainder\r
- beyond the end of the div_t structure if r.rem is narrower than 64-bits.\r
-\r
- Even though most implementations make long long 64 bits wide, we still go\r
- through bigrem, just-in-case.\r
-*/\r
-lldiv_t\r
-lldiv(long long num, long long denom)\r
-{\r
- lldiv_t r;\r
- INT64 bigrem;\r
-\r
- r.quot = (long long)DivS64x64Remainder( (INT64)num, (INT64)denom, &bigrem);\r
- r.rem = (long long)bigrem;\r
-\r
- return (r);\r
-}\r