fpu_hyperb.c revision 1.6 1 1.6 tsutsui /* $NetBSD: fpu_hyperb.c,v 1.6 2011/10/15 15:14:30 tsutsui 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.6 tsutsui __KERNEL_RCSID(0, "$NetBSD: fpu_hyperb.c,v 1.6 2011/10/15 15:14:30 tsutsui 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 fe->fe_fpsr &= ~FPSR_EXCP; /* clear all exceptions */
85 1.6 tsutsui
86 1.6 tsutsui if (ISNAN(&fe->fe_f2))
87 1.6 tsutsui return &fe->fe_f2;
88 1.6 tsutsui
89 1.6 tsutsui if (ISINF(&fe->fe_f2)) {
90 1.6 tsutsui fe->fe_f2.fp_sign = 0;
91 1.6 tsutsui return &fe->fe_f2;
92 1.6 tsutsui }
93 1.6 tsutsui
94 1.6 tsutsui fpu_const(&s0, 0x32); /* 1.0 */
95 1.6 tsutsui r = fpu_sincos_taylor(fe, &s0, 1, hyperb);
96 1.6 tsutsui CPYFPN(&fe->fe_f2, r);
97 1.6 tsutsui
98 1.6 tsutsui fpu_upd_fpsr(fe, &fe->fe_f2);
99 1.5 isaki return &fe->fe_f2;
100 1.1 briggs }
101 1.1 briggs
102 1.1 briggs struct fpn *
103 1.4 dsl fpu_sinh(struct fpemu *fe)
104 1.1 briggs {
105 1.6 tsutsui struct fpn s0;
106 1.6 tsutsui struct fpn *r;
107 1.6 tsutsui int hyperb = 1;
108 1.6 tsutsui
109 1.6 tsutsui fe->fe_fpsr &= ~FPSR_EXCP; /* clear all exceptions */
110 1.6 tsutsui
111 1.6 tsutsui if (ISNAN(&fe->fe_f2))
112 1.6 tsutsui return &fe->fe_f2;
113 1.6 tsutsui if (ISINF(&fe->fe_f2))
114 1.6 tsutsui return &fe->fe_f2;
115 1.6 tsutsui
116 1.6 tsutsui CPYFPN(&s0, &fe->fe_f2);
117 1.6 tsutsui r = fpu_sincos_taylor(fe, &s0, 2, hyperb);
118 1.6 tsutsui CPYFPN(&fe->fe_f2, r);
119 1.6 tsutsui
120 1.6 tsutsui fpu_upd_fpsr(fe, &fe->fe_f2);
121 1.5 isaki return &fe->fe_f2;
122 1.1 briggs }
123 1.1 briggs
124 1.1 briggs struct fpn *
125 1.4 dsl fpu_tanh(struct fpemu *fe)
126 1.1 briggs {
127 1.6 tsutsui struct fpn x;
128 1.6 tsutsui struct fpn s;
129 1.6 tsutsui struct fpn *r;
130 1.6 tsutsui int sign;
131 1.6 tsutsui
132 1.6 tsutsui fe->fe_fpsr &= ~FPSR_EXCP; /* clear all exceptions */
133 1.6 tsutsui
134 1.6 tsutsui if (ISNAN(&fe->fe_f2))
135 1.6 tsutsui return &fe->fe_f2;
136 1.6 tsutsui
137 1.6 tsutsui if (ISINF(&fe->fe_f2)) {
138 1.6 tsutsui sign = fe->fe_f2.fp_sign;
139 1.6 tsutsui fpu_const(&fe->fe_f2, 0x32);
140 1.6 tsutsui fe->fe_f2.fp_sign = sign;
141 1.6 tsutsui return &fe->fe_f2;
142 1.6 tsutsui }
143 1.6 tsutsui
144 1.6 tsutsui CPYFPN(&x, &fe->fe_f2);
145 1.6 tsutsui
146 1.6 tsutsui /* sinh(x) */
147 1.6 tsutsui CPYFPN(&fe->fe_f2, &x);
148 1.6 tsutsui r = fpu_sinh(fe);
149 1.6 tsutsui CPYFPN(&s, r);
150 1.6 tsutsui
151 1.6 tsutsui /* cosh(x) */
152 1.6 tsutsui CPYFPN(&fe->fe_f2, &x);
153 1.6 tsutsui r = fpu_cosh(fe);
154 1.6 tsutsui CPYFPN(&fe->fe_f2, r);
155 1.6 tsutsui
156 1.6 tsutsui CPYFPN(&fe->fe_f1, &s);
157 1.6 tsutsui r = fpu_div(fe);
158 1.6 tsutsui
159 1.6 tsutsui CPYFPN(&fe->fe_f2, r);
160 1.6 tsutsui
161 1.6 tsutsui fpu_upd_fpsr(fe, &fe->fe_f2);
162 1.5 isaki return &fe->fe_f2;
163 1.1 briggs }
164