[BACK]Return to thyperbolic.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gmp / mpfr / tests

Annotation of OpenXM_contrib/gmp/mpfr/tests/thyperbolic.c, Revision 1.1.1.1

1.1       ohara       1: /* Test file for hyperbolic function : mpfr_cosh, mpfr_sinh, mpfr_tanh, mpfr_acosh, mpfr_asinh, mpfr_atanh.
                      2:
                      3: Copyright 2001, 2002 Free Software Foundation, Inc.
                      4:
                      5: This file is part of the MPFR Library.
                      6:
                      7: The MPFR 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
                      9: by
                     10: the Free Software Foundation; either version 2.1 of the License, or (at youroption) any later version.
                     11:
                     12: The MPFR Library is distributed in the hope that it will be useful, but
                     13: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITYor FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
                     14: License for more details.
                     15:
                     16: You should have received a copy of the GNU Lesser General Public License
                     17: along with the MPFR Library; see the file COPYING.LIB.  If not, write to
                     18: the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
                     19: MA 02111-1307, USA. */
                     20:
                     21: #include <stdio.h>
                     22: #include "gmp.h"
                     23: #include "gmp-impl.h"
                     24: #include "mpfr.h"
                     25: #include "mpfr-impl.h"
                     26:
                     27:
                     28: int check_O _PROTO((void));
                     29: int check_NAN _PROTO((void));
                     30: int check_zero _PROTO((void));
                     31: int check_INF _PROTO((void));
                     32:
                     33:
                     34:
                     35: int
                     36: check_NAN (void)
                     37: {
                     38:
                     39:  mpfr_t t, ch,sh,th,ach,ash,ath;
                     40:  int tester;
                     41:
                     42:  mpfr_init2(t,200);
                     43:  mpfr_init2(ch,200);
                     44:  mpfr_init2(sh,200);
                     45:  mpfr_init2(th,200);
                     46:  mpfr_init2(ach,200);
                     47:  mpfr_init2(ash,200);
                     48:  mpfr_init2(ath,200);
                     49:
                     50:  MPFR_SET_NAN(t);
                     51:
                     52:   /******cosh********/
                     53:
                     54:   tester=mpfr_cosh(ch,t,GMP_RNDD);
                     55:   if (!MPFR_IS_NAN(ch) || tester!=0 )
                     56:   {
                     57:     printf("cosh NAN \n");
                     58:     mpfr_clear(t);
                     59:     mpfr_clear(ch);
                     60:     mpfr_clear(sh);
                     61:     mpfr_clear(th);
                     62:     mpfr_clear(ach);
                     63:     mpfr_clear(ash);
                     64:     mpfr_clear(ath);
                     65:     return(1);
                     66:   }
                     67:
                     68:   /******sinh********/
                     69:
                     70:   tester=mpfr_sinh(sh,t,GMP_RNDD);
                     71:   if (!MPFR_IS_NAN(sh) || tester!=0 )
                     72:   {
                     73:     printf("sinh NAN \n");
                     74:     mpfr_clear(t);
                     75:     mpfr_clear(ch);
                     76:     mpfr_clear(sh);
                     77:     mpfr_clear(th);
                     78:     mpfr_clear(ach);
                     79:     mpfr_clear(ash);
                     80:     mpfr_clear(ath);
                     81:     return(1);
                     82:   }
                     83:
                     84:   /******tanh********/
                     85:
                     86:   tester=mpfr_tanh(th,t,GMP_RNDD);
                     87:   if (!MPFR_IS_NAN(th) || tester!=0 )
                     88:   {
                     89:     printf("tanh NAN \n");
                     90:     mpfr_clear(t);
                     91:     mpfr_clear(ch);
                     92:     mpfr_clear(sh);
                     93:     mpfr_clear(th);
                     94:     mpfr_clear(ach);
                     95:     mpfr_clear(ash);
                     96:     mpfr_clear(ath);
                     97:     return(1);
                     98:   }
                     99:
                    100:   /******acosh********/
                    101:
                    102:   tester=mpfr_acosh(ach,t,GMP_RNDD);
                    103:   if (!MPFR_IS_NAN(ach) || tester!=0 )
                    104:   {
                    105:     printf("acosh NAN \n");
                    106:     return(1);
                    107:   }
                    108:
                    109:   /******asinh********/
                    110:
                    111:   tester=mpfr_asinh(ash,t,GMP_RNDD);
                    112:   if (!MPFR_IS_NAN(ash) || tester!=0 )
                    113:   {
                    114:     printf("asinh NAN \n");
                    115:     mpfr_clear(t);
                    116:     mpfr_clear(ch);
                    117:     mpfr_clear(sh);
                    118:     mpfr_clear(th);
                    119:     mpfr_clear(ach);
                    120:     mpfr_clear(ash);
                    121:     mpfr_clear(ath);
                    122:     return(1);
                    123:   }
                    124:
                    125:   /******atanh********/
                    126:
                    127:   tester=mpfr_atanh(ath,t,GMP_RNDD);
                    128:   if (!MPFR_IS_NAN(ath) || tester!=0 )
                    129:   {
                    130:     printf("atanh NAN \n");
                    131:     mpfr_clear(t);
                    132:     mpfr_clear(ch);
                    133:     mpfr_clear(sh);
                    134:     mpfr_clear(th);
                    135:     mpfr_clear(ach);
                    136:     mpfr_clear(ash);
                    137:     mpfr_clear(ath);
                    138:     return(1);
                    139:   }
                    140:
                    141:   mpfr_clear(t);
                    142:   mpfr_clear(ch);
                    143:   mpfr_clear(sh);
                    144:   mpfr_clear(th);
                    145:   mpfr_clear(ach);
                    146:   mpfr_clear(ash);
                    147:   mpfr_clear(ath);
                    148:
                    149:   return(0);
                    150:
                    151: }
                    152: int
                    153: check_zero (void)
                    154: {
                    155:
                    156:  mpfr_t t, ch,sh,th,ach,ash,ath;
                    157:  int tester;
                    158:
                    159:  mpfr_init2(t,200);
                    160:  mpfr_init2(ch,200);
                    161:  mpfr_init2(sh,200);
                    162:  mpfr_init2(th,200);
                    163:  mpfr_init2(ach,200);
                    164:  mpfr_init2(ash,200);
                    165:  mpfr_init2(ath,200);
                    166:
                    167:
                    168:  mpfr_set_ui(t,0,GMP_RNDD);
                    169:
                    170:   /******cosh********/
                    171:
                    172:   tester=mpfr_cosh(ch,t,GMP_RNDD);
                    173:   if (!mpfr_cmp_ui(ch,1) || !tester )
                    174:   {
                    175:     printf("cosh(0) \n");
                    176:     mpfr_clear(t);
                    177:     mpfr_clear(ch);
                    178:     mpfr_clear(sh);
                    179:     mpfr_clear(th);
                    180:     mpfr_clear(ach);
                    181:     mpfr_clear(ash);
                    182:     mpfr_clear(ath);
                    183:     return(1);
                    184:   }
                    185:
                    186:   /******sinh********/
                    187:
                    188:   tester=mpfr_sinh(sh,t,GMP_RNDD);
                    189:   if (!MPFR_IS_ZERO(sh) || !tester )
                    190:   {
                    191:     printf("sinh(0) \n");
                    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:     return(1);
                    200:   }
                    201:
                    202:   /******tanh********/
                    203:
                    204:   tester=mpfr_tanh(th,t,GMP_RNDD);
                    205:   if (!MPFR_IS_ZERO(th) || !tester )
                    206:   {
                    207:     printf("tanh(0) \n");
                    208:    mpfr_clear(t);
                    209:    mpfr_clear(ch);
                    210:    mpfr_clear(sh);
                    211:    mpfr_clear(th);
                    212:    mpfr_clear(ach);
                    213:    mpfr_clear(ash);
                    214:    mpfr_clear(ath);
                    215:    return(1);
                    216:   }
                    217:
                    218:   /******acosh********/
                    219:
                    220:   tester=mpfr_acosh(ach,t,GMP_RNDD);
                    221:   if (!MPFR_IS_NAN(ach) || tester != -1 )
                    222:   {
                    223:     printf("acosh(0) \n");
                    224:     mpfr_clear(t);
                    225:     mpfr_clear(ch);
                    226:     mpfr_clear(sh);
                    227:     mpfr_clear(th);
                    228:     mpfr_clear(ach);
                    229:     mpfr_clear(ash);
                    230:     mpfr_clear(ath);
                    231:     return(1);
                    232:   }
                    233:
                    234:   /******asinh********/
                    235:
                    236:   tester=mpfr_asinh(ash,t,GMP_RNDD);
                    237:   if (!MPFR_IS_ZERO(ash) || !tester )
                    238:   {
                    239:     printf("asinh(0) \n");
                    240:     mpfr_clear(t);
                    241:     mpfr_clear(ch);
                    242:     mpfr_clear(sh);
                    243:     mpfr_clear(th);
                    244:     mpfr_clear(ach);
                    245:     mpfr_clear(ash);
                    246:     mpfr_clear(ath);
                    247:     return(1);
                    248:   }
                    249:
                    250:   /******atanh********/
                    251:
                    252:   tester=mpfr_atanh(ath,t,GMP_RNDD);
                    253:   if (!MPFR_IS_ZERO(ath) || !tester )
                    254:   {
                    255:     printf("atanh(0) \n");
                    256:     mpfr_clear(t);
                    257:     mpfr_clear(ch);
                    258:     mpfr_clear(sh);
                    259:     mpfr_clear(th);
                    260:     mpfr_clear(ach);
                    261:     mpfr_clear(ash);
                    262:     mpfr_clear(ath);
                    263:     return(1);
                    264:   }
                    265:
                    266:   mpfr_clear(t);
                    267:   mpfr_clear(ch);
                    268:   mpfr_clear(sh);
                    269:   mpfr_clear(th);
                    270:   mpfr_clear(ach);
                    271:   mpfr_clear(ash);
                    272:   mpfr_clear(ath);
                    273:
                    274:   return(0);
                    275:
                    276: }
                    277:
                    278: int
                    279: check_INF (void)
                    280: {
                    281:
                    282:  mpfr_t t, ch,sh,th,ach,ash,ath;
                    283:  int tester;
                    284:
                    285:
                    286:  mpfr_init2(t,200);
                    287:  mpfr_init2(ch,200);
                    288:  mpfr_init2(sh,200);
                    289:  mpfr_init2(th,200);
                    290:  mpfr_init2(ach,200);
                    291:  mpfr_init2(ash,200);
                    292:  mpfr_init2(ath,200);
                    293:
                    294:  MPFR_CLEAR_NAN(t);
                    295:  MPFR_SET_INF(t);
                    296:
                    297:  if(MPFR_SIGN(t)<0)
                    298:    MPFR_CHANGE_SIGN(t);
                    299:
                    300:   /******cosh********/
                    301:
                    302:   tester = mpfr_cosh(ch,t,GMP_RNDD);
                    303:   if (!MPFR_IS_INF(ch) || MPFR_SIGN(ch) < 0 || tester!=0 )
                    304:   {
                    305:     printf("cosh(INF) \n");
                    306:     mpfr_clear(t);
                    307:     mpfr_clear(ch);
                    308:     mpfr_clear(sh);
                    309:     mpfr_clear(th);
                    310:     mpfr_clear(ach);
                    311:     mpfr_clear(ash);
                    312:     mpfr_clear(ath);
                    313:     return(1);
                    314:   }
                    315:
                    316:   /******sinh********/
                    317:
                    318:   tester=mpfr_sinh(sh,t,GMP_RNDD);
                    319:   if (!MPFR_IS_INF(sh) || MPFR_SIGN(sh) < 0  || tester!=0 )
                    320:   {
                    321:     printf("sinh(INF) \n");
                    322:     mpfr_clear(t);
                    323:     mpfr_clear(ch);
                    324:     mpfr_clear(sh);
                    325:     mpfr_clear(th);
                    326:     mpfr_clear(ach);
                    327:     mpfr_clear(ash);
                    328:     mpfr_clear(ath);
                    329:     return(1);
                    330:   }
                    331:
                    332:   /******tanh********/
                    333:
                    334:   tester=mpfr_tanh(th,t,GMP_RNDD);
                    335:   if (mpfr_cmp_ui(th,1) != 0 || tester!=0 )
                    336:   {
                    337:     printf("tanh(INF) \n");
                    338:     mpfr_clear(t);
                    339:     mpfr_clear(ch);
                    340:     mpfr_clear(sh);
                    341:     mpfr_clear(th);
                    342:     mpfr_clear(ach);
                    343:     mpfr_clear(ash);
                    344:     mpfr_clear(ath);
                    345:     return(1);
                    346:   }
                    347:
                    348:   /******acosh********/
                    349:
                    350:   tester=mpfr_acosh(ach,t,GMP_RNDD);
                    351:   if (!MPFR_IS_INF(ach) || MPFR_SIGN(ach) < 0  || tester!=0 )
                    352:   {
                    353:     printf("acosh(INF) \n");
                    354:     mpfr_clear(t);
                    355:     mpfr_clear(ch);
                    356:     mpfr_clear(sh);
                    357:     mpfr_clear(th);
                    358:     mpfr_clear(ach);
                    359:     mpfr_clear(ash);
                    360:     mpfr_clear(ath);
                    361:     return(1);
                    362:   }
                    363:
                    364:   /******asinh********/
                    365:
                    366:   tester=mpfr_asinh(ash,t,GMP_RNDD);
                    367:   if (!MPFR_IS_INF(ash) || MPFR_SIGN(ash) < 0  || tester!=0 )
                    368:   {
                    369:     printf("asinh(INF) \n");
                    370:     mpfr_clear(t);
                    371:     mpfr_clear(ch);
                    372:     mpfr_clear(sh);
                    373:     mpfr_clear(th);
                    374:     mpfr_clear(ach);
                    375:     mpfr_clear(ash);
                    376:     mpfr_clear(ath);
                    377:     return(1);
                    378:   }
                    379:
                    380:   /******atanh********/
                    381:
                    382:   tester=mpfr_atanh(ath,t,GMP_RNDD);
                    383:   if (!MPFR_IS_INF(ath) || tester != 0)
                    384:   {
                    385:     printf("atanh(INF) \n");
                    386:     mpfr_clear(t);
                    387:     mpfr_clear(ch);
                    388:     mpfr_clear(sh);
                    389:     mpfr_clear(th);
                    390:     mpfr_clear(ach);
                    391:     mpfr_clear(ash);
                    392:     mpfr_clear(ath);
                    393:     return(1);
                    394:   }
                    395:
                    396:  MPFR_CHANGE_SIGN(t);
                    397:
                    398:   /******cosh********/
                    399:
                    400:   tester=mpfr_cosh(ch,t,GMP_RNDD);
                    401:   if (!MPFR_IS_INF(ch) || MPFR_SIGN(ch) < 0  || tester!=0 )
                    402:   {
                    403:     printf("cosh(-INF) \n");
                    404:     mpfr_clear(t);
                    405:     mpfr_clear(ch);
                    406:     mpfr_clear(sh);
                    407:     mpfr_clear(th);
                    408:     mpfr_clear(ach);
                    409:     mpfr_clear(ash);
                    410:     mpfr_clear(ath);
                    411:     return(1);
                    412:   }
                    413:
                    414:   /******sinh********/
                    415:
                    416:   tester=mpfr_sinh(sh,t,GMP_RNDD);
                    417:   if (!MPFR_IS_INF(sh)  || MPFR_SIGN(sh) > 0 || tester!=0 )
                    418:   {
                    419:     printf("sinh(-INF) \n");
                    420:     mpfr_clear(t);
                    421:     mpfr_clear(ch);
                    422:     mpfr_clear(sh);
                    423:     mpfr_clear(th);
                    424:     mpfr_clear(ach);
                    425:     mpfr_clear(ash);
                    426:     mpfr_clear(ath);
                    427:     return(1);
                    428:   }
                    429:
                    430:   /******tanh********/
                    431:
                    432:   tester=mpfr_tanh(th,t,GMP_RNDD);
                    433:   if (!mpfr_cmp_ui(th,-1) || tester!=0 )
                    434:   {
                    435:     printf("tanh(-INF) \n");
                    436:     mpfr_clear(t);
                    437:     mpfr_clear(ch);
                    438:     mpfr_clear(sh);
                    439:     mpfr_clear(th);
                    440:     mpfr_clear(ach);
                    441:     mpfr_clear(ash);
                    442:     mpfr_clear(ath);
                    443:     return(1);
                    444:   }
                    445:
                    446:   /******acosh********/
                    447:
                    448:   tester=mpfr_acosh(ach,t,GMP_RNDD);
                    449:   if (!MPFR_IS_INF(ach) || MPFR_SIGN(ach) < 0  || tester!=0 )
                    450:   {
                    451:     printf("acosh(-INF) \n");
                    452:     mpfr_clear(t);
                    453:     mpfr_clear(ch);
                    454:     mpfr_clear(sh);
                    455:     mpfr_clear(th);
                    456:     mpfr_clear(ach);
                    457:     mpfr_clear(ash);
                    458:     mpfr_clear(ath);
                    459:     return(1);
                    460:   }
                    461:
                    462:   /******asinh********/
                    463:
                    464:   tester=mpfr_asinh(ash,t,GMP_RNDD);
                    465:   if (!MPFR_IS_INF(ash) || MPFR_SIGN(ash) > 0  || tester!=0 )
                    466:   {
                    467:     printf("asinh(-INF) \n");
                    468:     mpfr_clear(t);
                    469:     mpfr_clear(ch);
                    470:     mpfr_clear(sh);
                    471:     mpfr_clear(th);
                    472:     mpfr_clear(ach);
                    473:     mpfr_clear(ash);
                    474:     mpfr_clear(ath);
                    475:     return(1);
                    476:   }
                    477:
                    478:   /******atanh********/
                    479:
                    480:   tester=mpfr_atanh(ath,t,GMP_RNDD);
                    481:   if (!MPFR_IS_INF(ath) || MPFR_SIGN(ath) > 0 || tester != 0 )
                    482:   {
                    483:     printf("atanh(-INF) \n");
                    484:     mpfr_clear(t);
                    485:     mpfr_clear(ch);
                    486:     mpfr_clear(sh);
                    487:     mpfr_clear(th);
                    488:     mpfr_clear(ach);
                    489:     mpfr_clear(ash);
                    490:     mpfr_clear(ath);
                    491:    return(1);
                    492:   }
                    493:
                    494:   mpfr_clear(t);
                    495:   mpfr_clear(ch);
                    496:   mpfr_clear(sh);
                    497:   mpfr_clear(th);
                    498:   mpfr_clear(ach);
                    499:   mpfr_clear(ash);
                    500:   mpfr_clear(ath);
                    501:
                    502:
                    503:   return(0);
                    504:
                    505: }
                    506:
                    507: int
                    508: check_O (void)
                    509: {
                    510:
                    511:  mpfr_t t, ch,sh,th,ach,ash,ath;
                    512:
                    513:  mpfr_init2(t,20);
                    514:  mpfr_init2(ch,40);
                    515:  mpfr_init2(sh,40);
                    516:  mpfr_init2(th,40);
                    517:  mpfr_init2(ach,40);
                    518:  mpfr_init2(ash,40);
                    519:  mpfr_init2(ath,40);
                    520:
                    521:  mpfr_set_ui(t,2,GMP_RNDD);
                    522:
                    523:  /******acosh o cosh********/
                    524:
                    525:   mpfr_cosh(ch,t,GMP_RNDN);
                    526:   mpfr_acosh(ach,ch,GMP_RNDN);
                    527:   if(mpfr_cmp_ui(ach,2)!=0)
                    528:   {
                    529:     printf("cosh o acosh \n");
                    530:     mpfr_clear(t);
                    531:     mpfr_clear(ch);
                    532:     mpfr_clear(sh);
                    533:     mpfr_clear(th);
                    534:     mpfr_clear(ach);
                    535:     mpfr_clear(ash);
                    536:     mpfr_clear(ath);
                    537:     return(1);
                    538:   }
                    539:
                    540:   /******asinh o sinh********/
                    541:
                    542:   mpfr_sinh(sh,t,GMP_RNDN);
                    543:   mpfr_asinh(ash,sh,GMP_RNDN);
                    544:   if(mpfr_cmp_ui(ash,2)!=0)
                    545:   {
                    546:     printf("sinh o asinh \n");
                    547:     mpfr_clear(t);
                    548:     mpfr_clear(ch);
                    549:     mpfr_clear(sh);
                    550:     mpfr_clear(th);
                    551:     mpfr_clear(ach);
                    552:     mpfr_clear(ash);
                    553:     mpfr_clear(ath);
                    554:     return(1);
                    555:   }
                    556:
                    557:
                    558:   /******atanh o tanh********/
                    559:
                    560:   mpfr_tanh(th,t,GMP_RNDN);
                    561:   mpfr_atanh(ath,th,GMP_RNDU);
                    562:
                    563:   /*
                    564:   mpfr_out_str(stdout, 2,40,th,GMP_RNDN);
                    565:   putchar('\n');
                    566:
                    567:   mpfr_out_str(stdout, 2,40,ath,GMP_RNDU);
                    568:   putchar('\n');
                    569:   */
                    570:
                    571:   if(mpfr_cmp_ui(ath,2)!=0)
                    572:   {
                    573:     printf("tanh o atanh \n");
                    574:     mpfr_clear(t);
                    575:     mpfr_clear(ch);
                    576:     mpfr_clear(sh);
                    577:     mpfr_clear(th);
                    578:     mpfr_clear(ach);
                    579:     mpfr_clear(ash);
                    580:     mpfr_clear(ath);
                    581:     return(1);
                    582:   }
                    583:
                    584:   mpfr_clear(t);
                    585:   mpfr_clear(ch);
                    586:   mpfr_clear(sh);
                    587:   mpfr_clear(th);
                    588:   mpfr_clear(ach);
                    589:   mpfr_clear(ash);
                    590:   mpfr_clear(ath);
                    591:
                    592:  return(0);
                    593:
                    594: }
                    595:
                    596: int
                    597: main(void)
                    598: {
                    599:
                    600: if (check_INF())printf("Error in evaluation of INF\n");
                    601: if (check_NAN())printf("Error in evaluation of NAN\n");
                    602: /*if (check_O())printf("Error in evaluation of composition hyperbolic function\n");*/
                    603:
                    604: return(0);
                    605:
                    606:
                    607: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>