📄 t-equal.c
字号:
/* Test mpq_equal.Copyright 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"voidcheck_one (mpq_srcptr x, mpq_srcptr y, int want){ int got; MPQ_CHECK_FORMAT (x); MPQ_CHECK_FORMAT (y); got = mpq_equal (x, y); if ((got != 0) != (want != 0)) { printf ("mpq_equal got %d want %d\n", got, want); mpq_trace ("x", x); mpq_trace ("y", y); abort (); }}voidcheck_all (mpq_ptr x, mpq_ptr y, int want){ check_one (x, y, want); check_one (y, x, want); mpq_neg (x, x); mpq_neg (y, y); check_one (x, y, want); check_one (y, x, want);}#define SET4Z(z, size,l3,l2,l1,l0) \ SIZ(z) = size; PTR(z)[3] = l3; PTR(z)[2] = l2; PTR(z)[1] = l1; PTR(z)[0] = l0#define SET4(q, nsize,n3,n2,n1,n0, dsize,d3,d2,d1,d0) \ SET4Z (mpq_numref(q), nsize,n3,n2,n1,n0); \ SET4Z (mpq_denref(q), dsize,d3,d2,d1,d0)/* Exercise various combinations of same and slightly different values. */voidcheck_various (void){ mpq_t x, y; mpq_init (x); mpq_init (y); mpz_realloc (mpq_numref(x), (mp_size_t) 20); mpz_realloc (mpq_denref(x), (mp_size_t) 20); mpz_realloc (mpq_numref(y), (mp_size_t) 20); mpz_realloc (mpq_denref(y), (mp_size_t) 20); /* 0 == 0 */ SET4 (x, 0,13,12,11,10, 1,23,22,21,1); SET4 (y, 0,33,32,31,30, 1,43,42,41,1); check_all (x, y, 1); /* 83/99 == 83/99 */ SET4 (x, 1,13,12,11,83, 1,23,22,21,99); SET4 (y, 1,33,32,31,83, 1,43,42,41,99); check_all (x, y, 1); /* 1:2:3:4/5:6:7 == 1:2:3:4/5:6:7 */ SET4 (x, 4,1,2,3,4, 3,88,5,6,7); SET4 (y, 4,1,2,3,4, 3,99,5,6,7); check_all (x, y, 1); /* various individual changes making != */ SET4 (x, 4,1,2,3,667, 3,88,5,6,7); SET4 (y, 4,1,2,3,4, 3,99,5,6,7); check_all (x, y, 0); SET4 (x, 4,1,2,666,4, 3,88,5,6,7); SET4 (y, 4,1,2,3,4, 3,99,5,6,7); check_all (x, y, 0); SET4 (x, 4,1,666,3,4, 3,88,5,6,7); SET4 (y, 4,1,2,3,4, 3,99,5,6,7); check_all (x, y, 0); SET4 (x, 4,667,2,3,4, 3,88,5,6,7); SET4 (y, 4,1,2,3,4, 3,99,5,6,7); check_all (x, y, 0); SET4 (x, 4,1,2,3,4, 3,88,5,6,667); SET4 (y, 4,1,2,3,4, 3,99,5,6,7); check_all (x, y, 0); SET4 (x, 4,1,2,3,4, 3,88,5,667,7); SET4 (y, 4,1,2,3,4, 3,99,5,6,7); check_all (x, y, 0); SET4 (x, 4,1,2,3,4, 3,88,666,6,7); SET4 (y, 4,1,2,3,4, 3,99,5,6,7); check_all (x, y, 0); SET4 (x, -4,1,2,3,4, 3,88,5,6,7); SET4 (y, 4,1,2,3,4, 3,99,5,6,7); check_all (x, y, 0); SET4 (x, 1,1,2,3,4, 3,88,5,6,7); SET4 (y, 4,1,2,3,4, 3,99,5,6,7); check_all (x, y, 0); mpq_clear (x); mpq_clear (y);}intmain (void){ tests_start (); mp_trace_base = -16; check_various (); tests_end (); exit (0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -