(root)/
mpfr-4.2.1/
tests/
thyperbolic.c
       1  /* Test file for hyperbolic function : mpfr_cosh, mpfr_sinh, mpfr_tanh, mpfr_acosh, mpfr_asinh, mpfr_atanh.
       2  
       3  Copyright 2001-2004, 2006-2023 Free Software Foundation, Inc.
       4  Contributed by the AriC and Caramba projects, INRIA.
       5  
       6  This file is part of the GNU MPFR Library.
       7  
       8  The GNU MPFR Library is free software; you can redistribute it and/or modify
       9  it under the terms of the GNU Lesser General Public License as published by
      10  the Free Software Foundation; either version 3 of the License, or (at your
      11  option) any later version.
      12  
      13  The GNU MPFR Library is distributed in the hope that it will be useful, but
      14  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
      15  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
      16  License for more details.
      17  
      18  You should have received a copy of the GNU Lesser General Public License
      19  along with the GNU MPFR Library; see the file COPYING.LESSER.  If not, see
      20  https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
      21  51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
      22  
      23  #include "mpfr-test.h"
      24  
      25  static int
      26  check_NAN (void)
      27  {
      28    mpfr_t t, ch,sh,th,ach,ash,ath;
      29    int tester;
      30    int fail = 0;
      31  
      32    mpfr_init2(t,200);
      33    mpfr_init2(ch,200);
      34    mpfr_init2(sh,200);
      35    mpfr_init2(th,200);
      36    mpfr_init2(ach,200);
      37    mpfr_init2(ash,200);
      38    mpfr_init2(ath,200);
      39  
      40    MPFR_SET_NAN(t);
      41  
      42    /******cosh********/
      43  
      44    tester=mpfr_cosh(ch,t,MPFR_RNDD);
      45    if (!MPFR_IS_NAN(ch) || tester!=0)
      46      {
      47        printf("cosh NAN \n");
      48        fail = 1;
      49        goto clean_up;
      50      }
      51  
      52    /******sinh********/
      53  
      54    tester=mpfr_sinh(sh,t,MPFR_RNDD);
      55    if (!MPFR_IS_NAN(sh) || tester!=0)
      56      {
      57        printf("sinh NAN \n");
      58        fail = 1;
      59        goto clean_up;
      60      }
      61  
      62    /******tanh********/
      63  
      64    tester=mpfr_tanh(th,t,MPFR_RNDD);
      65    if (!MPFR_IS_NAN(th) || tester!=0)
      66      {
      67        printf("tanh NAN \n");
      68        fail = 1;
      69        goto clean_up;
      70      }
      71  
      72    /******acosh********/
      73  
      74    tester=mpfr_acosh(ach,t,MPFR_RNDD);
      75    if (!MPFR_IS_NAN(ach) || tester!=0)
      76      {
      77        printf("acosh NAN \n");
      78        fail = 1;
      79        goto clean_up;
      80      }
      81  
      82    /******asinh********/
      83  
      84    tester=mpfr_asinh(ash,t,MPFR_RNDD);
      85    if (!MPFR_IS_NAN(ash) || tester!=0)
      86      {
      87        printf("asinh NAN \n");
      88        fail = 1;
      89        goto clean_up;
      90      }
      91  
      92    /******atanh********/
      93  
      94    tester=mpfr_atanh(ath,t,MPFR_RNDD);
      95    if (!MPFR_IS_NAN(ath) || tester!=0)
      96      {
      97        printf("atanh NAN \n");
      98        fail = 1;
      99        goto clean_up;
     100      }
     101  
     102   clean_up:
     103    mpfr_clear(t);
     104    mpfr_clear(ch);
     105    mpfr_clear(sh);
     106    mpfr_clear(th);
     107    mpfr_clear(ach);
     108    mpfr_clear(ash);
     109    mpfr_clear(ath);
     110  
     111    return fail;
     112  }
     113  
     114  static int
     115  check_zero (void)
     116  {
     117    mpfr_t t, ch,sh,th,ach,ash,ath;
     118    int tester;
     119    int fail = 0;
     120  
     121    mpfr_init2(t,200);
     122    mpfr_init2(ch,200);
     123    mpfr_init2(sh,200);
     124    mpfr_init2(th,200);
     125    mpfr_init2(ach,200);
     126    mpfr_init2(ash,200);
     127    mpfr_init2(ath,200);
     128  
     129    mpfr_set_ui(t,0,MPFR_RNDD);
     130  
     131    /******cosh********/
     132  
     133    tester = mpfr_cosh (ch, t, MPFR_RNDD);
     134    if (mpfr_cmp_ui(ch, 1) || tester)
     135      {
     136        printf("cosh(0) \n");
     137        fail = 1;
     138        goto clean_up;
     139      }
     140  
     141    /******sinh********/
     142  
     143    tester = mpfr_sinh (sh, t, MPFR_RNDD);
     144    if (!MPFR_IS_ZERO(sh) || tester)
     145      {
     146        printf("sinh(0) \n");
     147        fail = 1;
     148        goto clean_up;
     149      }
     150  
     151    /******tanh********/
     152  
     153    tester = mpfr_tanh (th, t, MPFR_RNDD);
     154    if (!MPFR_IS_ZERO(th) || tester)
     155      {
     156        printf("tanh(0) \n");
     157        fail = 1;
     158        goto clean_up;
     159      }
     160  
     161    /******acosh********/
     162  
     163    tester=mpfr_acosh(ach,t,MPFR_RNDD);
     164    if (!MPFR_IS_NAN(ach) || tester)
     165      {
     166        printf("acosh(0) \n");
     167        fail = 1;
     168        goto clean_up;
     169      }
     170  
     171    /******asinh********/
     172  
     173    tester=mpfr_asinh(ash,t,MPFR_RNDD);
     174    if (!MPFR_IS_ZERO(ash) || tester)
     175      {
     176        printf("asinh(0) \n");
     177        fail = 1;
     178        goto clean_up;
     179      }
     180  
     181    /******atanh********/
     182  
     183    tester=mpfr_atanh(ath,t,MPFR_RNDD);
     184    if (!MPFR_IS_ZERO(ath) || tester)
     185      {
     186        printf("atanh(0) \n");
     187        fail = 1;
     188        goto clean_up;
     189      }
     190  
     191   clean_up:
     192    mpfr_clear(t);
     193    mpfr_clear(ch);
     194    mpfr_clear(sh);
     195    mpfr_clear(th);
     196    mpfr_clear(ach);
     197    mpfr_clear(ash);
     198    mpfr_clear(ath);
     199  
     200    return fail;
     201  }
     202  
     203  static int
     204  check_INF (void)
     205  {
     206    mpfr_t t, ch, sh, th, ach, ash, ath;
     207    int tester;
     208    int fail = 0;
     209  
     210    mpfr_init2 (t, 200);
     211    mpfr_init2 (ch, 200);
     212    mpfr_init2 (sh, 200);
     213    mpfr_init2 (th, 200);
     214    mpfr_init2 (ach, 200);
     215    mpfr_init2 (ash, 200);
     216    mpfr_init2 (ath, 200);
     217  
     218    MPFR_SET_INF(t);
     219  
     220    if(MPFR_IS_NEG (t))
     221      MPFR_CHANGE_SIGN(t);
     222  
     223    /******cosh********/
     224  
     225    tester = mpfr_cosh(ch,t,MPFR_RNDD);
     226    if (!MPFR_IS_INF(ch) || MPFR_IS_NEG (ch) || tester!=0)
     227      {
     228        printf("cosh(INF) \n");
     229        fail = 1;
     230        goto clean_up;
     231      }
     232  
     233    /******sinh********/
     234  
     235    tester=mpfr_sinh(sh,t,MPFR_RNDD);
     236    if (!MPFR_IS_INF(sh) || MPFR_IS_NEG (sh)  || tester!=0)
     237      {
     238        printf("sinh(INF) \n");
     239        fail = 1;
     240        goto clean_up;
     241      }
     242  
     243    /******tanh********/
     244  
     245    tester=mpfr_tanh(th,t,MPFR_RNDD);
     246    if (mpfr_cmp_ui(th,1) != 0 || tester!=0)
     247      {
     248        printf("tanh(INF) \n");
     249        fail = 1;
     250        goto clean_up;
     251      }
     252  
     253    /******acosh********/
     254  
     255    tester=mpfr_acosh(ach,t,MPFR_RNDD);
     256    if (!MPFR_IS_INF(ach) || MPFR_IS_NEG (ach)  || tester!=0)
     257      {
     258        printf("acosh(INF) \n");
     259        fail = 1;
     260        goto clean_up;
     261      }
     262  
     263    /******asinh********/
     264  
     265    tester=mpfr_asinh(ash,t,MPFR_RNDD);
     266    if (!MPFR_IS_INF(ash) || MPFR_IS_NEG (ash)  || tester!=0)
     267      {
     268        printf("asinh(INF) \n");
     269        fail = 1;
     270        goto clean_up;
     271      }
     272  
     273    /******atanh********/
     274  
     275    tester = mpfr_atanh (ath, t, MPFR_RNDD);
     276    if (!MPFR_IS_NAN(ath) || tester != 0)
     277      {
     278        printf("atanh(INF) \n");
     279        fail = 1;
     280        goto clean_up;
     281      }
     282  
     283    MPFR_CHANGE_SIGN(t);
     284  
     285    /******cosh********/
     286  
     287    tester=mpfr_cosh(ch,t,MPFR_RNDD);
     288    if (!MPFR_IS_INF(ch) || MPFR_IS_NEG (ch)  || tester!=0)
     289      {
     290        printf("cosh(-INF) \n");
     291        fail = 1;
     292        goto clean_up;
     293      }
     294  
     295    /******sinh********/
     296  
     297    tester=mpfr_sinh(sh,t,MPFR_RNDD);
     298    if (!MPFR_IS_INF(sh)  || MPFR_IS_POS (sh) || tester!=0)
     299      {
     300        printf("sinh(-INF) \n");
     301        fail = 1;
     302        goto clean_up;
     303      }
     304  
     305    /******tanh********/
     306  
     307    tester=mpfr_tanh(th,t,MPFR_RNDD);
     308    if (!mpfr_cmp_ui(th,-1) || tester!=0)
     309      {
     310        printf("tanh(-INF) \n");
     311        fail = 1;
     312        goto clean_up;
     313      }
     314  
     315    /******acosh********/
     316  
     317    tester=mpfr_acosh(ach,t,MPFR_RNDD);
     318    if (!MPFR_IS_NAN(ach) || tester!=0)
     319      {
     320        printf("acosh(-INF) \n");
     321        fail = 1;
     322        goto clean_up;
     323      }
     324  
     325    /******asinh********/
     326  
     327    tester=mpfr_asinh(ash,t,MPFR_RNDD);
     328    if (!MPFR_IS_INF(ash) || MPFR_IS_POS (ash)  || tester!=0)
     329      {
     330        printf("asinh(-INF) \n");
     331        fail = 1;
     332        goto clean_up;
     333      }
     334  
     335    /******atanh********/
     336  
     337    tester = mpfr_atanh (ath, t, MPFR_RNDD);
     338    if (!MPFR_IS_NAN(ath) || tester != 0)
     339      {
     340        printf("atanh(-INF) \n");
     341        fail = 1;
     342        goto clean_up;
     343      }
     344  
     345   clean_up:
     346    mpfr_clear(t);
     347    mpfr_clear(ch);
     348    mpfr_clear(sh);
     349    mpfr_clear(th);
     350    mpfr_clear(ach);
     351    mpfr_clear(ash);
     352    mpfr_clear(ath);
     353  
     354    return fail;
     355  }
     356  
     357  int
     358  main(void)
     359  {
     360    tests_start_mpfr ();
     361  
     362    if (check_zero ())
     363      {
     364        printf ("Error in evaluation at 0\n");
     365        exit (1);
     366      }
     367  
     368    if (check_INF ())
     369      {
     370        printf ("Error in evaluation of INF\n");
     371        exit (1);
     372      }
     373  
     374    if (check_NAN ())
     375      {
     376        printf ("Error in evaluation of NAN\n");
     377        exit (1);
     378      }
     379  
     380    tests_end_mpfr ();
     381    return 0;
     382  }