⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reuse.c

📁 a very popular packet of cryptography tools,it encloses the most common used algorithm and protocols
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Test file for in-place operations.Copyright 2000, 2001, 2002 Free Software Foundation.This file is part of the MPFR Library.The MPFR 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 MPFR 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 MPFR 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 "mpfr.h"#include "mpfr-impl.h"typedef void (*fct_t)();fct_t testfunc;void test3 _PROTO ((char *, mp_prec_t, mp_rnd_t));void test4 _PROTO ((char *, mp_prec_t, mp_rnd_t));void test3a _PROTO ((char *, mp_prec_t, mp_rnd_t));void test2ui _PROTO ((char *, mp_prec_t, mp_rnd_t));void testui2 _PROTO ((char *, mp_prec_t, mp_rnd_t));void test2 _PROTO ((char *, mp_prec_t, mp_rnd_t));void test2a _PROTO ((char *, mp_prec_t));int mpfr_compare _PROTO ((mpfr_t, mpfr_t));/* same than mpfr_cmp, but returns 0 for both NaN's */intmpfr_compare (mpfr_t a, mpfr_t b){  return (MPFR_IS_NAN(a)) ? !MPFR_IS_NAN(b) :     (MPFR_IS_NAN(b) || mpfr_cmp(a, b));}voidtest3 (char *foo, mp_prec_t prec, mp_rnd_t rnd){  mpfr_t ref1, ref2, ref3;  mpfr_t res1;  int i;#ifdef DEBUG  printf("checking %s\n", foo);#endif  mpfr_init2 (ref1, prec);  mpfr_init2 (ref2, prec);  mpfr_init2 (ref3, prec);  mpfr_init2 (res1, prec);  /* for each variable, consider each of the following 6 possibilities:     NaN, +Infinity, -Infinity, +0, -0 or a random number */  for (i=0; i<36; i++) {    if (i%6==0) mpfr_set_nan (ref2);    if (i%6==1) mpfr_set_inf (ref2, 1);    if (i%6==2) mpfr_set_inf (ref2, -1);    if (i%6==3) mpfr_set_d (ref2, 0.0, GMP_RNDN);    if (i%6==4) mpfr_set_d (ref2, -0.0, GMP_RNDN);    if (i%6==5) mpfr_random (ref2);    if (i/6==0) mpfr_set_nan (ref3);    if (i/6==1) mpfr_set_inf (ref3, 1);    if (i/6==2) mpfr_set_inf (ref3, -1);    if (i/6==3) mpfr_set_d (ref3, 0.0, GMP_RNDN);    if (i/6==4) mpfr_set_d (ref3, -0.0, GMP_RNDN);    if (i/6==5) mpfr_random (ref3);    /* reference call: foo(a, b, c) */    testfunc (ref1, ref2, ref3, rnd);     /* foo(a, a, c) */    mpfr_set (res1, ref2, rnd); /* exact operation */    testfunc (res1, res1, ref3, rnd);     if (mpfr_compare (res1, ref1)) {      fprintf (stderr, "Error for %s(a, a, c) for a=%e, c=%e\n", foo,	       mpfr_get_d1 (ref2), mpfr_get_d1 (ref3));      fprintf (stderr, "expected %e, got %e\n", mpfr_get_d1 (ref1),	       mpfr_get_d1 (res1));      exit (1);    }    /* foo(a, b, a) */    mpfr_set (res1, ref3, rnd);    testfunc (res1, ref2, res1, rnd);    if (mpfr_compare (res1, ref1)) {      fprintf (stderr, "Error for %s(a, b, a) for b=%e, a=%e\n", foo,	       mpfr_get_d1 (ref2), mpfr_get_d1 (ref3));      fprintf (stderr, "expected %e, got %e\n", mpfr_get_d1 (ref1),	       mpfr_get_d1 (res1));      exit (1);    }    /* foo(a, a, a) */    mpfr_set (ref3, ref2, rnd);    testfunc (ref1, ref2, ref3, rnd);    mpfr_set (res1, ref2, rnd);    testfunc (res1, res1, res1, rnd);   if (mpfr_compare (res1, ref1)) {      fprintf (stderr, "Error for %s(a, a, a) for a=%e\n", foo,	       mpfr_get_d1 (ref2));      fprintf (stderr, "expected %e, got %e\n", mpfr_get_d1 (ref1),	       mpfr_get_d1 (res1));      exit (1);    }  }  mpfr_clear (ref1);  mpfr_clear (ref2);  mpfr_clear (ref3);  mpfr_clear (res1);}voidtest4 (char *foo, mp_prec_t prec, mp_rnd_t rnd){  mpfr_t ref, op1, op2, op3;  mpfr_t res;  int i, j, k;#ifdef DEBUG  printf("checking %s\n", foo);#endif  mpfr_init2 (ref, prec);  mpfr_init2 (op1, prec);  mpfr_init2 (op2, prec);  mpfr_init2 (op3, prec);  mpfr_init2 (res, prec);  /* for each variable, consider each of the following 6 possibilities:     NaN, +Infinity, -Infinity, +0, -0 or a random number */  for (i=0; i<6; i++)     {      MPFR_CLEAR_FLAGS(op1);      if (i==0) mpfr_set_nan (op1);      if (i==1) mpfr_set_inf (op1, 1);      if (i==2) mpfr_set_inf (op1, -1);      if (i==3) mpfr_set_d (op1, 0.0, GMP_RNDN);      if (i==4) mpfr_set_d (op1, -0.0, GMP_RNDN);      if (i==5) mpfr_random (op1);            for (j=0; j<6; j++)         {          MPFR_CLEAR_FLAGS(op2);          if (j==0) mpfr_set_nan (op2);          if (j==1) mpfr_set_inf (op2, 1);          if (j==2) mpfr_set_inf (op2, -1);          if (j==3) mpfr_set_d (op2, 0.0, GMP_RNDN);          if (j==4) mpfr_set_d (op2, -0.0, GMP_RNDN);          if (j==5) mpfr_random (op2);          for (k=0; k<6; k++)             {              MPFR_CLEAR_FLAGS(op3);              if (k==0) mpfr_set_nan (op3);              if (k==1) mpfr_set_inf (op3, 1);              if (k==2) mpfr_set_inf (op3, -1);              if (k==3) mpfr_set_d (op3, 0.0, GMP_RNDN);              if (k==4) mpfr_set_d (op3, -0.0, GMP_RNDN);              if (k==5) mpfr_random (op3);              /* reference call: foo(s, a, b, c) */              testfunc (ref, op1, op2, op3, rnd);               /* foo(a, a, b, c) */              mpfr_set (res, op1, rnd); /* exact operation */              testfunc (res, res, op2, op3, rnd);               if (mpfr_compare (res, ref))               {                fprintf (stderr,                          "Error for %s(a, a, b, c) for a=%e, b=%e, c=%e\n",                          foo,                         mpfr_get_d1 (op1), mpfr_get_d1 (op2), mpfr_get_d1 (op3));                fprintf (stderr, "expected %e, got %e\n", mpfr_get_d1 (ref),                         mpfr_get_d1 (res));                exit (1);              }              /* foo(b, a, b, c) */              mpfr_set (res, op2, rnd);              testfunc (res, op1, res, op3, rnd);             if (mpfr_compare (res, ref))               {                fprintf (stderr,                          "Error for %s(b, a, b, c) for a=%e, b=%e, c=%e\n",                          foo,                         mpfr_get_d1 (op1), mpfr_get_d1 (op2), mpfr_get_d1 (op3));                fprintf (stderr, "expected %e, got %e\n", mpfr_get_d1 (ref),                         mpfr_get_d1 (res));                exit (1);              }              /* foo(c, a, b, c) */              mpfr_set (res, op3, rnd);              testfunc (res, op1, op2, res, rnd);             if (mpfr_compare (res, ref))               {                fprintf (stderr,                          "Error for %s(c, a, b, c) for a=%e, b=%e, c=%e\n",                         foo,                         mpfr_get_d1 (op1), mpfr_get_d1 (op2), mpfr_get_d1 (op3));                fprintf (stderr, "expected %e, got %e\n", mpfr_get_d1 (ref),                         mpfr_get_d1 (res));                exit (1);              }              /* foo(a, a, a,c) */             testfunc (ref, op1, op1, op3, rnd);             mpfr_set (res, op1, rnd);             testfunc (res, res, res, op3, rnd);             if (mpfr_compare (res, ref))               {                fprintf (stderr,                          "Error for %s(a, a, a, c) for a=%e, a=%e, c=%e\n",                         foo,                         mpfr_get_d1 (op1), mpfr_get_d1 (op2), mpfr_get_d1 (op3));                fprintf (stderr, "expected %e, got %e\n", mpfr_get_d1 (ref),                         mpfr_get_d1 (res));                exit (1);              }              /* foo(a, a, b,a) */              testfunc (ref, op1, op2, op1, rnd);              mpfr_set (res, op1, rnd);              testfunc (res, res, op2, res, rnd);              if (mpfr_compare (res, ref))                {                 fprintf (stderr,                           "Error for %s(a, a, b, a) for a=%e, a=%e, c=%e\n",                          foo,                       mpfr_get_d1 (op1), mpfr_get_d1 (op2), mpfr_get_d1 (op3));                 fprintf (stderr, "expected %e, got %e\n", mpfr_get_d1 (ref),                          mpfr_get_d1 (res));                 exit (1);               }              /* foo(b, a, b, b) */              testfunc (ref, op1, op2, op2, rnd);              mpfr_set (res, op2, rnd);              testfunc (res, op1, res, res, rnd);              if (mpfr_compare (res, ref))                {                 fprintf (stderr,                           "Error for %s(b, a, b, b) for a=%e, a=%e, c=%e\n",                           foo,                        mpfr_get_d1 (op1), mpfr_get_d1 (op2), mpfr_get_d1 (op3));                 fprintf (stderr, "expected %e, got %e\n", mpfr_get_d1 (ref),                          mpfr_get_d1 (res));                 exit (1);               }              /* foo (a, a, a, a) */              testfunc (ref, op1, op1, op1 ,rnd);              mpfr_set (res, op1, rnd);              testfunc (res, res, res, res, rnd);              if (mpfr_compare (res, ref))                {                 fprintf (stderr,                          "Error for %s(a, a, a, a) for a=%e\n", foo,                          mpfr_get_d1 (op1));                 fprintf (stderr, "expected %e, got %e\n", mpfr_get_d1 (ref),                          mpfr_get_d1 (res));                 exit (1);               }            }        }    }  mpfr_clear (ref);  mpfr_clear (op1);  mpfr_clear (op2);  mpfr_clear (op3);  mpfr_clear (res);}voidtest2ui (char *foo, mp_prec_t prec, mp_rnd_t rnd)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -