📄 t-perfsqr.c
字号:
/* Test mpz_perfect_square_p and mpz_perfect_power_pCopyright 2000, 2001 Free Software Foundation, Inc.This file is part of the GNU MP Library.The GNU MP Library is free software; you can redistribute it and/or modifyit under the terms of the GNU Lesser General Public License as published bythe Free Software Foundation; either version 2.1 of the License, or (at youroption) any later version.The GNU MP Library is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITYor FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General PublicLicense for more details.You should have received a copy of the GNU Lesser General Public Licensealong with the GNU MP Library; see the file COPYING.LIB. If not, write tothe Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,MA 02111-1307, USA. */#include <stdio.h>#include <stdlib.h>#include "gmp.h"#include "gmp-impl.h"#include "tests.h"void debug_mp _PROTO ((mpz_t, int));intmain (int argc, char **argv){ mpz_t x2, x2t, x; mp_size_t x2n; int res; int i; /* int cnt = 0; */ int reps = 100000; gmp_randstate_ptr rands; mpz_t bs; tests_start (); rands = RANDS; mpz_init (bs); if (argc == 2) reps = atoi (argv[1]); mpz_init (x2); mpz_init (x); mpz_init (x2t); for (i = 0; i < reps; i++) { mpz_urandomb (bs, rands, 9); x2n = mpz_get_ui (bs); mpz_rrandomb (x2, rands, x2n); /* mpz_out_str (stdout, -16, x2); puts (""); */ res = mpz_perfect_square_p (x2); mpz_sqrt (x, x2); mpz_mul (x2t, x, x); if (res != (mpz_cmp (x2, x2t) == 0)) abort (); /* cnt += res != 0; */ } /* printf ("%d/%d perfect squares\n", cnt, reps); */ mpz_clear (bs); mpz_clear (x2); mpz_clear (x); mpz_clear (x2t); tests_end (); exit (0);}voiddebug_mp (mpz_t x, int base){ mpz_out_str (stderr, base, x); fputc ('\n', stderr);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -