1 1.1 mrg /* Test mpf_set_ui and mpf_init_set_ui. 2 1.1 mrg 3 1.1 mrg Copyright 2000, 2001, 2003 Free Software Foundation, Inc. 4 1.1 mrg 5 1.1.1.2 mrg This file is part of the GNU MP Library test suite. 6 1.1 mrg 7 1.1.1.2 mrg The GNU MP Library test suite is free software; you can redistribute it 8 1.1.1.2 mrg and/or modify it under the terms of the GNU General Public License as 9 1.1.1.2 mrg published by the Free Software Foundation; either version 3 of the License, 10 1.1.1.2 mrg or (at your option) any later version. 11 1.1.1.2 mrg 12 1.1.1.2 mrg The GNU MP Library test suite is distributed in the hope that it will be 13 1.1.1.2 mrg useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 14 1.1.1.2 mrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 15 1.1.1.2 mrg Public License for more details. 16 1.1 mrg 17 1.1.1.2 mrg You should have received a copy of the GNU General Public License along with 18 1.1.1.3 mrg the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */ 19 1.1 mrg 20 1.1 mrg #include <stdio.h> 21 1.1 mrg #include <stdlib.h> 22 1.1 mrg #include "gmp-impl.h" 23 1.1 mrg #include "tests.h" 24 1.1 mrg 25 1.1 mrg void 26 1.1 mrg check_data (void) 27 1.1 mrg { 28 1.1 mrg static const struct { 29 1.1 mrg unsigned long x; 30 1.1 mrg mp_size_t want_size; 31 1.1 mrg mp_limb_t want_data[2]; 32 1.1 mrg } data[] = { 33 1.1 mrg 34 1.1 mrg { 0L, 0 }, 35 1.1 mrg { 1L, 1, { 1 } }, 36 1.1 mrg 37 1.1 mrg #if GMP_NUMB_BITS >= BITS_PER_ULONG 38 1.1 mrg { ULONG_MAX, 1, { ULONG_MAX, 0 } }, 39 1.1 mrg { ULONG_HIGHBIT, 1, { ULONG_HIGHBIT, 0 } }, 40 1.1 mrg #else 41 1.1 mrg { ULONG_MAX, 2, { ULONG_MAX & GMP_NUMB_MASK, 42 1.1 mrg ULONG_MAX >> GMP_NUMB_BITS } }, 43 1.1.1.2 mrg { ULONG_HIGHBIT, 2, { 0, 44 1.1 mrg ULONG_HIGHBIT >> GMP_NUMB_BITS } }, 45 1.1 mrg #endif 46 1.1 mrg }; 47 1.1 mrg 48 1.1 mrg mpf_t x; 49 1.1 mrg int i; 50 1.1 mrg 51 1.1 mrg for (i = 0; i < numberof (data); i++) 52 1.1 mrg { 53 1.1 mrg mpf_init (x); 54 1.1 mrg mpf_set_ui (x, data[i].x); 55 1.1 mrg MPF_CHECK_FORMAT (x); 56 1.1 mrg if (x->_mp_size != data[i].want_size 57 1.1 mrg || refmpn_cmp_allowzero (x->_mp_d, data[i].want_data, 58 1.1 mrg ABS (data[i].want_size)) != 0 59 1.1 mrg || x->_mp_exp != ABS (data[i].want_size)) 60 1.1 mrg { 61 1.1 mrg printf ("mpf_set_ui wrong on data[%d]\n", i); 62 1.1 mrg abort(); 63 1.1 mrg } 64 1.1 mrg mpf_clear (x); 65 1.1 mrg 66 1.1 mrg mpf_init_set_ui (x, data[i].x); 67 1.1 mrg MPF_CHECK_FORMAT (x); 68 1.1 mrg if (x->_mp_size != data[i].want_size 69 1.1 mrg || refmpn_cmp_allowzero (x->_mp_d, data[i].want_data, 70 1.1 mrg ABS (data[i].want_size)) != 0 71 1.1 mrg || x->_mp_exp != ABS (data[i].want_size)) 72 1.1 mrg { 73 1.1 mrg printf ("mpf_init_set_ui wrong on data[%d]\n", i); 74 1.1 mrg abort(); 75 1.1 mrg } 76 1.1 mrg mpf_clear (x); 77 1.1 mrg } 78 1.1 mrg } 79 1.1 mrg 80 1.1 mrg int 81 1.1 mrg main (void) 82 1.1 mrg { 83 1.1 mrg tests_start (); 84 1.1 mrg 85 1.1 mrg check_data (); 86 1.1 mrg 87 1.1 mrg tests_end (); 88 1.1 mrg exit (0); 89 1.1 mrg } 90