Imported Upstream version 2.9.0
[debian/cc1111] / device / lib / pic / libsdcc / _modschar.c
1 /* ---------------------------------------------------------------------------
2    _modschar.c : 8 bit modulus routines for pic14 devices
3
4         Written By      Raphael Neider <rneider AT web.de> (2005)
5
6    This library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Library General Public
8    License as published by the Free Software Foundation; either
9    version 2 of the License, or (at your option) any later version.
10
11    This library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Library General Public License for more details.
15
16    You should have received a copy of the GNU Library General Public
17    License along with this library; if not, write to the 
18    Free Software Foundation, Inc., 59 Temple Place - Suite 330, 
19    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    $Id: _modschar.c 4148 2006-05-01 20:47:12Z tecodev $
26    ------------------------------------------------------------------------ */
27
28 extern unsigned char _moduchar (unsigned char a, unsigned char b);
29
30 signed char
31 _modschar (signed char a, signed char b)
32 {
33   if (a < 0) {
34     /* a < 0 */
35     if (b < 0)
36       return _moduchar ((unsigned int)-a, (unsigned int)-b);
37     else
38       return -_moduchar ((unsigned int)-a, (unsigned int)b);
39   } else {
40     /* a >= 0 */
41     if (b < 0)
42       return -_moduchar ((unsigned int)a, (unsigned int)-b);
43     else
44       return _moduchar ((unsigned int)a, (unsigned int)b);
45   }
46   /* we never reach here */
47 }
48