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