186368Smike/*- 286368Smike * Copyright (c) 2001 Mike Barcroft <mike@FreeBSD.org> 386368Smike * All rights reserved. 486368Smike * 586368Smike * Redistribution and use in source and binary forms, with or without 686368Smike * modification, are permitted provided that the following conditions 786368Smike * are met: 886368Smike * 1. Redistributions of source code must retain the above copyright 986368Smike * notice, this list of conditions and the following disclaimer. 1086368Smike * 2. Redistributions in binary form must reproduce the above copyright 1186368Smike * notice, this list of conditions and the following disclaimer in the 1286368Smike * documentation and/or other materials provided with the distribution. 1386368Smike * 1486368Smike * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1586368Smike * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1686368Smike * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1786368Smike * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1886368Smike * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1986368Smike * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2086368Smike * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2186368Smike * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2286368Smike * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2386368Smike * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2486368Smike * SUCH DAMAGE. 2586368Smike */ 2686368Smike 2786368Smike#include <sys/cdefs.h> 2886368Smike__FBSDID("$FreeBSD: releng/10.2/lib/libc/stdlib/imaxdiv.c 86368 2001-11-15 02:05:03Z mike $"); 2986368Smike 3086368Smike#include <inttypes.h> 3186368Smike 3286368Smike/* See comments in div.c for implementation details. */ 3386368Smikeimaxdiv_t 3486368Smikeimaxdiv(intmax_t numer, intmax_t denom) 3586368Smike{ 3686368Smike imaxdiv_t retval; 3786368Smike 3886368Smike retval.quot = numer / denom; 3986368Smike retval.rem = numer % denom; 4086368Smike if (numer >= 0 && retval.rem < 0) { 4186368Smike retval.quot++; 4286368Smike retval.rem -= denom; 4386368Smike } 4486368Smike return (retval); 4586368Smike} 46