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