source: trunk/third/gmp/tests/mpbsd/t-itom.c @ 18191

Revision 18191, 1.7 KB checked in by ghudson, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18190, which included commits to RCS files with non-trunk default branches.
Line 
1/* Test itom.
2
3Copyright 2000, 2001 Free Software Foundation, Inc.
4
5This file is part of the GNU MP Library.
6
7The GNU MP Library is free software; you can redistribute it and/or modify
8it under the terms of the GNU Lesser General Public License as published by
9the Free Software Foundation; either version 2.1 of the License, or (at your
10option) any later version.
11
12The GNU MP Library is distributed in the hope that it will be useful, but
13WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
15License for more details.
16
17You should have received a copy of the GNU Lesser General Public License
18along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
19the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20MA 02111-1307, USA. */
21
22#include <stdio.h>
23#include <stdlib.h>
24#include "gmp.h"
25#include "gmp-impl.h"
26#include "mp.h"
27#include "tests.h"
28
29#define SGN(x)       ((x) < 0 ? -1 : (x) == 0 ? 0 : 1)
30
31
32void
33check_data (void)
34{
35  static const struct {
36    short      m;
37    mp_size_t  want_size;
38    mp_limb_t  want_limb;
39  } data[] = {
40
41    {  0L,  0 },
42    {  1L,  1, 1 },
43    { -1L, -1, 1 },
44
45    {  SHRT_MAX,  1,  SHRT_MAX },
46    { -SHRT_MAX, -1,  SHRT_MAX },
47    {  SHRT_MIN, -1, -SHRT_MIN },
48  };
49
50  MINT  *m;
51  int   i;
52
53  for (i = 0; i < numberof (data); i++)
54    {
55      m = itom (data[i].m);
56      if (m->_mp_size != data[i].want_size
57          || (m->_mp_size != 0 && m->_mp_d[0] != data[i].want_limb))
58        {
59          printf ("itom wrong on data[%d]\n", i);
60          abort();                                   
61        }
62      mfree (m);
63    }
64}
65
66
67int
68main (void)
69{
70  tests_start ();
71
72  check_data ();
73
74  tests_end ();
75  exit (0);
76}
Note: See TracBrowser for help on using the repository browser.