1/* Test file for mpfr_log10. 2 3Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. 4Contributed by the Arenaire and Cacao projects, INRIA. 5 6This file is part of the GNU MPFR Library. 7 8The GNU MPFR Library is free software; you can redistribute it and/or modify 9it under the terms of the GNU Lesser General Public License as published by 10the Free Software Foundation; either version 3 of the License, or (at your 11option) any later version. 12 13The GNU MPFR Library is distributed in the hope that it will be useful, but 14WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 15or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 16License for more details. 17 18You should have received a copy of the GNU Lesser General Public License 19along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see 20http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., 2151 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ 22 23#include <stdio.h> 24#include <stdlib.h> 25 26#include "mpfr-test.h" 27 28#ifdef CHECK_EXTERNAL 29static int 30test_log10 (mpfr_ptr a, mpfr_srcptr b, mpfr_rnd_t rnd_mode) 31{ 32 int res; 33 int ok = rnd_mode == MPFR_RNDN && mpfr_number_p (b) && mpfr_get_prec (a)>=53; 34 if (ok) 35 { 36 mpfr_print_raw (b); 37 } 38 res = mpfr_log10 (a, b, rnd_mode); 39 if (ok) 40 { 41 printf (" "); 42 mpfr_print_raw (a); 43 printf ("\n"); 44 } 45 return res; 46} 47#else 48#define test_log10 mpfr_log10 49#endif 50 51#define TEST_FUNCTION test_log10 52#define TEST_RANDOM_POS 8 53#include "tgeneric.c" 54 55int 56main (int argc, char *argv[]) 57{ 58 mpfr_t x, y; 59 unsigned int n; 60 int inex; 61 62 tests_start_mpfr (); 63 64 test_generic (2, 100, 20); 65 66 mpfr_init2 (x, 53); 67 mpfr_init2 (y, 53); 68 69 /* check NaN */ 70 mpfr_set_nan (x); 71 inex = test_log10 (y, x, MPFR_RNDN); 72 MPFR_ASSERTN (mpfr_nan_p (y) && inex == 0); 73 74 /* check Inf */ 75 mpfr_set_inf (x, -1); 76 inex = test_log10 (y, x, MPFR_RNDN); 77 MPFR_ASSERTN (mpfr_nan_p (y) && inex == 0); 78 79 mpfr_set_inf (x, 1); 80 inex = test_log10 (y, x, MPFR_RNDN); 81 MPFR_ASSERTN (mpfr_inf_p (y) && mpfr_sgn (y) > 0 && inex == 0); 82 83 mpfr_set_ui (x, 0, MPFR_RNDN); 84 inex = test_log10 (x, x, MPFR_RNDN); 85 MPFR_ASSERTN (mpfr_inf_p (x) && mpfr_sgn (x) < 0 && inex == 0); 86 mpfr_set_ui (x, 0, MPFR_RNDN); 87 mpfr_neg (x, x, MPFR_RNDN); 88 inex = test_log10 (x, x, MPFR_RNDN); 89 MPFR_ASSERTN (mpfr_inf_p (x) && mpfr_sgn (x) < 0 && inex == 0); 90 91 /* check negative argument */ 92 mpfr_set_si (x, -1, MPFR_RNDN); 93 inex = test_log10 (y, x, MPFR_RNDN); 94 MPFR_ASSERTN (mpfr_nan_p (y) && inex == 0); 95 96 /* check log10(1) = 0 */ 97 mpfr_set_ui (x, 1, MPFR_RNDN); 98 inex = test_log10 (y, x, MPFR_RNDN); 99 MPFR_ASSERTN (mpfr_cmp_ui (y, 0) == 0 && MPFR_IS_POS (y) && inex == 0); 100 101 /* check log10(10^n)=n */ 102 mpfr_set_ui (x, 1, MPFR_RNDN); 103 for (n = 1; n <= 15; n++) 104 { 105 mpfr_mul_ui (x, x, 10, MPFR_RNDN); /* x = 10^n */ 106 inex = test_log10 (y, x, MPFR_RNDN); 107 if (mpfr_cmp_ui (y, n)) 108 { 109 printf ("log10(10^n) <> n for n=%u\n", n); 110 exit (1); 111 } 112 MPFR_ASSERTN (inex == 0); 113 } 114 115 mpfr_clear (x); 116 mpfr_clear (y); 117 118 data_check ("data/log10", mpfr_log10, "mpfr_log10"); 119 120 tests_end_mpfr (); 121 return 0; 122} 123