00001 /* 00002 This file is part of magpar. 00003 00004 Copyright (C) 2006-2010 Werner Scholz 00005 00006 www: http://www.magpar.net/ 00007 email: magpar(at)magpar.net 00008 00009 magpar is free software; you can redistribute it and/or modify 00010 it under the terms of the GNU General Public License as published by 00011 the Free Software Foundation; either version 2 of the License, or 00012 (at your option) any later version. 00013 00014 magpar is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU General Public License for more details. 00018 00019 You should have received a copy of the GNU General Public License 00020 along with magpar; if not, write to the Free Software 00021 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 */ 00023 00024 /* 00025 $Id: distint.c 2962 2010-02-04 19:50:44Z scholz $ 00026 */ 00027 00028 #include "util.h" 00029 00030 int distint(int from, int to, int in) 00031 { 00032 int out; 00033 if (from<=to) { 00034 out=in; 00035 } 00036 else { 00037 int i,j; 00038 00039 i=from/to; 00040 j=from%to; 00041 if (in<j*(i+1)) { 00042 out=in/(i+1); 00043 } 00044 else { 00045 out=(in-j)/i; 00046 } 00047 } 00048 00049 return(out); 00050 }