1/* Test file for mpfr_log1p. 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_log1p (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_log1p (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_log1p mpfr_log1p 49#endif 50 51#define TEST_FUNCTION test_log1p 52#define TEST_RANDOM_EMAX 80 53#include "tgeneric.c" 54 55static void 56special (void) 57{ 58 mpfr_t x; 59 int inex; 60 61 mpfr_init (x); 62 63 mpfr_set_nan (x); 64 inex = test_log1p (x, x, MPFR_RNDN); 65 MPFR_ASSERTN (mpfr_nan_p (x) && inex == 0); 66 67 mpfr_set_inf (x, -1); 68 inex = test_log1p (x, x, MPFR_RNDN); 69 MPFR_ASSERTN (mpfr_nan_p (x) && inex == 0); 70 71 mpfr_set_inf (x, 1); 72 inex = test_log1p (x, x, MPFR_RNDN); 73 MPFR_ASSERTN (mpfr_inf_p (x) && mpfr_sgn (x) > 0 && inex == 0); 74 75 mpfr_set_ui (x, 0, MPFR_RNDN); 76 inex = test_log1p (x, x, MPFR_RNDN); 77 MPFR_ASSERTN (mpfr_cmp_ui (x, 0) == 0 && MPFR_IS_POS (x) && inex == 0); 78 mpfr_neg (x, x, MPFR_RNDN); 79 inex = test_log1p (x, x, MPFR_RNDN); 80 MPFR_ASSERTN (mpfr_cmp_ui (x, 0) == 0 && MPFR_IS_NEG (x) && inex == 0); 81 82 mpfr_set_si (x, -1, MPFR_RNDN); 83 inex = test_log1p (x, x, MPFR_RNDN); 84 MPFR_ASSERTN (mpfr_inf_p (x) && mpfr_sgn (x) < 0 && inex == 0); 85 86 mpfr_set_si (x, -2, MPFR_RNDN); 87 inex = test_log1p (x, x, MPFR_RNDN); 88 MPFR_ASSERTN (mpfr_nan_p (x) && inex == 0); 89 90 mpfr_clear (x); 91} 92 93static void 94other (void) 95{ 96 mpfr_t x, y; 97 98 /* Bug reported by Guillaume Melquiond on 2006-08-14. */ 99 mpfr_init2 (x, 53); 100 mpfr_set_str (x, "-1.5e4f72873ed9a@-100", 16, MPFR_RNDN); 101 mpfr_init2 (y, 57); 102 mpfr_log1p (y, x, MPFR_RNDU); 103 if (mpfr_cmp (x, y) != 0) 104 { 105 printf ("Error in tlog1p for x = "); 106 mpfr_out_str (stdout, 16, 0, x, MPFR_RNDN); 107 printf (", rnd = MPFR_RNDU\nExpected "); 108 mpfr_out_str (stdout, 16, 15, x, MPFR_RNDN); 109 printf ("\nGot "); 110 mpfr_out_str (stdout, 16, 15, y, MPFR_RNDN); 111 printf ("\n"); 112 exit (1); 113 } 114 115 mpfr_clear (y); 116 mpfr_clear (x); 117 return; 118} 119 120int 121main (int argc, char *argv[]) 122{ 123 tests_start_mpfr (); 124 125 special (); 126 other (); 127 128 test_generic (2, 100, 50); 129 130 data_check ("data/log1p", mpfr_log1p, "mpfr_log1p"); 131 bad_cases (mpfr_log1p, mpfr_expm1, "mpfr_log1p", 256, -64, 40, 132 4, 128, 800, 40); 133 134 tests_end_mpfr (); 135 return 0; 136} 137