ldiv.c revision 251672
11897Swollman/* 21897Swollman * Copyright (c) 1990, 1993 31897Swollman * The Regents of the University of California. All rights reserved. 41897Swollman * 51897Swollman * This code is derived from software contributed to Berkeley by 61897Swollman * Chris Torek. 71897Swollman * 81897Swollman * Redistribution and use in source and binary forms, with or without 91897Swollman * modification, are permitted provided that the following conditions 101897Swollman * are met: 111897Swollman * 1. Redistributions of source code must retain the above copyright 121897Swollman * notice, this list of conditions and the following disclaimer. 131897Swollman * 2. Redistributions in binary form must reproduce the above copyright 141897Swollman * notice, this list of conditions and the following disclaimer in the 151897Swollman * documentation and/or other materials provided with the distribution. 161897Swollman * 3. Neither the name of the University nor the names of its contributors 171897Swollman * may be used to endorse or promote products derived from this software 181897Swollman * without specific prior written permission. 191897Swollman * 201897Swollman * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 211897Swollman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 221897Swollman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 231897Swollman * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 241897Swollman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 251897Swollman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 261897Swollman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 271897Swollman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 281897Swollman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 291897Swollman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 301897Swollman * SUCH DAMAGE. 311897Swollman */ 321897Swollman 331897Swollman#if defined(LIBC_SCCS) && !defined(lint) 341897Swollmanstatic char sccsid[] = "@(#)ldiv.c 8.1 (Berkeley) 6/4/93"; 351897Swollman#endif /* LIBC_SCCS and not lint */ 361897Swollman#include <sys/cdefs.h> 371897Swollman__FBSDID("$FreeBSD: head/lib/libc/stdlib/ldiv.c 251672 2013-06-13 00:19:30Z emaste $"); 381897Swollman 391897Swollman#include <stdlib.h> /* ldiv_t */ 401897Swollman 411897Swollmanldiv_t 421897Swollmanldiv(num, denom) 431897Swollman long num, denom; 441897Swollman{ 451897Swollman ldiv_t r; 461897Swollman 471897Swollman /* see div.c for comments */ 481897Swollman 491897Swollman r.quot = num / denom; 501897Swollman r.rem = num % denom; 511897Swollman if (num >= 0 && r.rem < 0) { 521897Swollman r.quot++; 531897Swollman r.rem -= denom; 541897Swollman } 551897Swollman return (r); 561897Swollman} 571897Swollman