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