Home | History | Annotate | Line # | Download | only in fpe
fpu_hyperb.c revision 1.8
      1 /*	$NetBSD: fpu_hyperb.c,v 1.8 2013/04/11 13:27:11 isaki Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1995  Ken Nakata
      5  *	All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. Neither the name of the author nor the names of its contributors
     16  *    may be used to endorse or promote products derived from this software
     17  *    without specific prior written permission.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29  * SUCH DAMAGE.
     30  *
     31  *	@(#)fpu_hyperb.c	10/24/95
     32  */
     33 
     34 /*
     35  * Copyright (c) 2011 Tetsuya Isaki. All rights reserved.
     36  *
     37  * Redistribution and use in source and binary forms, with or without
     38  * modification, are permitted provided that the following conditions
     39  * are met:
     40  * 1. Redistributions of source code must retain the above copyright
     41  *    notice, this list of conditions and the following disclaimer.
     42  * 2. Redistributions in binary form must reproduce the above copyright
     43  *    notice, this list of conditions and the following disclaimer in the
     44  *    documentation and/or other materials provided with the distribution.
     45  *
     46  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     47  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     48  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     49  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     50  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     51  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     52  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     53  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     54  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     55  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     56  * SUCH DAMAGE.
     57  */
     58 
     59 #include <sys/cdefs.h>
     60 __KERNEL_RCSID(0, "$NetBSD: fpu_hyperb.c,v 1.8 2013/04/11 13:27:11 isaki Exp $");
     61 
     62 #include "fpu_emulate.h"
     63 
     64 /*
     65  * fpu_hyperb.c: defines the following functions
     66  *
     67  *	fpu_atanh(), fpu_cosh(), fpu_sinh(), and fpu_tanh()
     68  */
     69 
     70 struct fpn *
     71 fpu_atanh(struct fpemu *fe)
     72 {
     73 	/* stub */
     74 	return &fe->fe_f2;
     75 }
     76 
     77 struct fpn *
     78 fpu_cosh(struct fpemu *fe)
     79 {
     80 	struct fpn s0;
     81 	struct fpn *r;
     82 	int hyperb = 1;
     83 
     84 	if (ISNAN(&fe->fe_f2))
     85 		return &fe->fe_f2;
     86 
     87 	if (ISINF(&fe->fe_f2)) {
     88 		fe->fe_f2.fp_sign = 0;
     89 		return &fe->fe_f2;
     90 	}
     91 
     92 	fpu_const(&s0, FPU_CONST_1);
     93 	r = fpu_sincos_taylor(fe, &s0, 1, hyperb);
     94 	CPYFPN(&fe->fe_f2, r);
     95 
     96 	return &fe->fe_f2;
     97 }
     98 
     99 struct fpn *
    100 fpu_sinh(struct fpemu *fe)
    101 {
    102 	struct fpn s0;
    103 	struct fpn *r;
    104 	int hyperb = 1;
    105 
    106 	if (ISNAN(&fe->fe_f2))
    107 		return &fe->fe_f2;
    108 	if (ISINF(&fe->fe_f2))
    109 		return &fe->fe_f2;
    110 
    111 	CPYFPN(&s0, &fe->fe_f2);
    112 	r = fpu_sincos_taylor(fe, &s0, 2, hyperb);
    113 	CPYFPN(&fe->fe_f2, r);
    114 
    115 	return &fe->fe_f2;
    116 }
    117 
    118 struct fpn *
    119 fpu_tanh(struct fpemu *fe)
    120 {
    121 	struct fpn x;
    122 	struct fpn s;
    123 	struct fpn *r;
    124 	int sign;
    125 
    126 	if (ISNAN(&fe->fe_f2))
    127 		return &fe->fe_f2;
    128 
    129 	if (ISINF(&fe->fe_f2)) {
    130 		sign = fe->fe_f2.fp_sign;
    131 		fpu_const(&fe->fe_f2, FPU_CONST_1);
    132 		fe->fe_f2.fp_sign = sign;
    133 		return &fe->fe_f2;
    134 	}
    135 
    136 	CPYFPN(&x, &fe->fe_f2);
    137 
    138 	/* sinh(x) */
    139 	CPYFPN(&fe->fe_f2, &x);
    140 	r = fpu_sinh(fe);
    141 	CPYFPN(&s, r);
    142 
    143 	/* cosh(x) */
    144 	CPYFPN(&fe->fe_f2, &x);
    145 	r = fpu_cosh(fe);
    146 	CPYFPN(&fe->fe_f2, r);
    147 
    148 	CPYFPN(&fe->fe_f1, &s);
    149 	r = fpu_div(fe);
    150 
    151 	CPYFPN(&fe->fe_f2, r);
    152 
    153 	return &fe->fe_f2;
    154 }
    155