1 /* Test mpf_cmp_d. 2 3 Copyright 2001, 2003, 2003, 2005 Free Software Foundation, Inc. 4 5 This file is part of the GNU MP Library. 6 7 The GNU MP Library is free software; you can redistribute it and/or modify 8 it under the terms of the GNU Lesser General Public License as published by 9 the Free Software Foundation; either version 3 of the License, or (at your 10 option) any later version. 11 12 The GNU MP Library is distributed in the hope that it will be useful, but 13 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 License for more details. 16 17 You should have received a copy of the GNU Lesser General Public License 18 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ 19 20 #include <stdio.h> 21 #include <stdlib.h> 22 #include <string.h> 23 24 #include "gmp.h" 25 #include "gmp-impl.h" 26 #include "tests.h" 27 28 29 #define SGN(n) ((n) > 0 ? 1 : (n) < 0 ? -1 : 0) 30 31 void 32 check_one (const char *name, mpf_srcptr x, double y, int cmp) 33 { 34 int got; 35 36 got = mpf_cmp_d (x, y); 37 if (SGN(got) != cmp) 38 { 39 int i; 40 printf ("mpf_cmp_d wrong (from %s)\n", name); 41 printf (" got %d\n", got); 42 printf (" want %d\n", cmp); 43 mpf_trace (" x", x); 44 printf (" y %g\n", y); 45 mp_trace_base=-16; 46 mpf_trace (" x", x); 47 printf (" y %g\n", y); 48 printf (" y"); 49 for (i = 0; i < sizeof(y); i++) 50 printf (" %02X", (unsigned) ((unsigned char *) &y)[i]); 51 printf ("\n"); 52 abort (); 53 } 54 } 55 56 void 57 check_infinity (void) 58 { 59 mpf_t x; 60 double y = tests_infinity_d (); 61 if (y == 0.0) 62 return; 63 64 mpf_init (x); 65 66 /* 0 cmp inf */ 67 mpf_set_ui (x, 0L); 68 check_one ("check_infinity", x, y, -1); 69 check_one ("check_infinity", x, -y, 1); 70 71 /* 123 cmp inf */ 72 mpf_set_ui (x, 123L); 73 check_one ("check_infinity", x, y, -1); 74 check_one ("check_infinity", x, -y, 1); 75 76 /* -123 cmp inf */ 77 mpf_set_si (x, -123L); 78 check_one ("check_infinity", x, y, -1); 79 check_one ("check_infinity", x, -y, 1); 80 81 /* 2^5000 cmp inf */ 82 mpf_set_ui (x, 1L); 83 mpf_mul_2exp (x, x, 5000L); 84 check_one ("check_infinity", x, y, -1); 85 check_one ("check_infinity", x, -y, 1); 86 87 /* -2^5000 cmp inf */ 88 mpf_neg (x, x); 89 check_one ("check_infinity", x, y, -1); 90 check_one ("check_infinity", x, -y, 1); 91 92 mpf_clear (x); 93 } 94 95 int 96 main (int argc, char *argv[]) 97 { 98 tests_start (); 99 100 check_infinity (); 101 102 tests_end (); 103 exit (0); 104 } 105