fp80_cvtd.c revision 9888:68d6b600d51f
1/* 2 * Copyright (c) 2013, Andreas Sandberg 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above 12 * copyright notice, this list of conditions and the following 13 * disclaimer in the documentation and/or other materials provided 14 * with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 19 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 20 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 27 * OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30#include <fputils/fp80.h> 31 32#include "test_helper.h" 33 34#include <math.h> 35#include <stdio.h> 36#include <stdlib.h> 37 38static void 39test_fp80_cvtd_class(const char *name, fp80_t fin, int class) 40{ 41 double d = fp80_cvtd(fin); 42 if (fpclassify(d) != class) { 43 test_diag("wrong class"); 44 test_fail(name); 45 } else { 46 test_ok(name); 47 } 48} 49 50static void 51test_fp80_cvtd_inf(const char *name, fp80_t fin, int inf_class) 52{ 53 double d = fp80_cvtd(fin); 54 if (isinf(d) != inf_class) { 55 test_diag("wrong infinity type"); 56 test_fail(name); 57 } else { 58 test_ok(name); 59 } 60} 61 62int 63main(int argc, char *argv[]) 64{ 65 test_init(6); 66 67 test_fp80_cvtd_inf("fp80->double +inf", fp80_pinf, 1); 68 test_fp80_cvtd_inf("fp80->double -inf", fp80_ninf, -1); 69 test_fp80_cvtd_class("fp80->double qnan", fp80_qnan, FP_NAN); 70 test_fp80_cvtd_class("fp80->double qnani", fp80_qnani, FP_NAN); 71 test_fp80_cvtd_class("fp80->double snan", fp80_snan, FP_NAN); 72 test_fp80_cvtd_class("fp80->double nan", fp80_nan, FP_NAN); 73 74 test_exit(); 75} 76