Imported Upstream version 2.9.0
[debian/cc1111] / device / lib / pic16 / libsdcc / int / divsint.c
1 /*-------------------------------------------------------------------------
2   _divsint.c :- routine for signed int (16 bit) division. just calls
3                 routine for unsigned division after sign adjustment
4
5              Written By -  Sandeep Dutta . sandeep.dutta@usa.net (1999)
6
7    This library is free software; you can redistribute it and/or modify it
8    under the terms of the GNU Library General Public License as published by the
9    Free Software Foundation; either version 2, or (at your option) any
10    later version.
11
12    This library is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU Library General Public License for more details.
16
17    You should have received a copy of the GNU Library General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
21    In other words, you are welcome to use, share and improve this program.
22    You are forbidden to forbid anyone else to use, share and improve
23    what you give them.   Help stamp out software-hoarding!
24 -------------------------------------------------------------------------*/
25
26 #include <sdcc-lib.h>
27
28 unsigned unsigned _divuint (unsigned a, unsigned b);
29
30 int _divsint (int a, int b) _IL_REENTRANT
31 {
32   register int r;
33
34   r = _divuint((a < 0 ? -a : a),
35                (b < 0 ? -b : b));
36   if ( (a < 0) ^ (b < 0))
37     return -r;
38   else
39     return r;
40 }
41