Upload Tizen:Base source
[external/gmp.git] / tests / mpbsd / t-itom.c
1 /* Test itom.
2
3 Copyright 2000, 2001 Free Software Foundation, Inc.
4
5 This file is part of the GNU MP Library.
6
7 The GNU MP Library is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11
12 The GNU MP Library is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
15 License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.  */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include "gmp.h"
23 #include "gmp-impl.h"
24 #include "mp.h"
25 #include "tests.h"
26
27 #define SGN(x)       ((x) < 0 ? -1 : (x) == 0 ? 0 : 1)
28
29
30 void
31 check_data (void)
32 {
33   static const struct {
34     short      m;
35     mp_size_t  want_size;
36     mp_limb_t  want_limb;
37   } data[] = {
38
39     {  0L,  0 },
40     {  1L,  1, 1 },
41     { -1L, -1, 1 },
42
43     {  SHRT_MAX,  1,  SHRT_MAX },
44     { -SHRT_MAX, -1,  SHRT_MAX },
45     {  SHRT_MIN, -1, -SHRT_MIN },
46   };
47
48   MINT  *m;
49   int   i;
50
51   for (i = 0; i < numberof (data); i++)
52     {
53       m = itom (data[i].m);
54       if (m->_mp_size != data[i].want_size
55           || (m->_mp_size != 0 && m->_mp_d[0] != data[i].want_limb))
56         {
57           printf ("itom wrong on data[%d]\n", i);
58           abort();
59         }
60       mfree (m);
61     }
62 }
63
64
65 int
66 main (void)
67 {
68   tests_start ();
69
70   check_data ();
71
72   tests_end ();
73   exit (0);
74 }