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