Rev 697 | Rev 731 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
535 | cejka | 1 | /* |
2 | * Copyright (C) 2005 Josef Cejka |
||
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 | * - Redistributions of source code must retain the above copyright |
||
10 | * notice, this list of conditions and the following disclaimer. |
||
11 | * - Redistributions in binary form must reproduce the above copyright |
||
12 | * notice, this list of conditions and the following disclaimer in the |
||
13 | * documentation and/or other materials provided with the distribution. |
||
14 | * - The name of the author may not be used to endorse or promote products |
||
15 | * derived from this software without specific prior written permission. |
||
16 | * |
||
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
||
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
||
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
||
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
27 | */ |
||
28 | |||
29 | #include<softfloat.h> |
||
647 | cejka | 30 | #include<sftypes.h> |
31 | #include<arithmetic.h> |
||
32 | #include<conversion.h> |
||
33 | #include<comparison.h> |
||
34 | #include<other.h> |
||
535 | cejka | 35 | |
647 | cejka | 36 | /* Arithmetic functions */ |
542 | cejka | 37 | |
38 | float __addsf3(float a, float b) |
||
39 | { |
||
40 | float32 fa, fb; |
||
563 | cejka | 41 | fa.f=a; |
42 | fb.f=b; |
||
647 | cejka | 43 | if (fa.parts.sign!=fb.parts.sign) { |
44 | if (fa.parts.sign) { |
||
45 | fa.parts.sign=0; |
||
46 | return subFloat32(fb,fa).f; |
||
47 | }; |
||
48 | fb.parts.sign=0; |
||
49 | return subFloat32(fa,fb).f; |
||
50 | } |
||
563 | cejka | 51 | return addFloat32(fa,fb).f; |
698 | cejka | 52 | } |
542 | cejka | 53 | |
54 | float __subsf3(float a, float b) |
||
55 | { |
||
56 | float32 fa, fb; |
||
563 | cejka | 57 | fa.f=a; |
58 | fb.f=b; |
||
647 | cejka | 59 | if (fa.parts.sign!=fb.parts.sign) { |
660 | cejka | 60 | fb.parts.sign=!fb.parts.sign; |
647 | cejka | 61 | return addFloat32(fa,fb).f; |
62 | } |
||
563 | cejka | 63 | return subFloat32(fa,fb).f; |
698 | cejka | 64 | } |
542 | cejka | 65 | |
688 | cejka | 66 | float __mulsf3(float a, float b) |
67 | { |
||
68 | float32 fa, fb; |
||
69 | fa.f=a; |
||
70 | fb.f=b; |
||
71 | return mulFloat32(fa, fb).f; |
||
72 | } |
||
73 | |||
697 | cejka | 74 | float __divsf3(float a, float b) |
75 | { |
||
76 | float32 fa, fb; |
||
77 | fa.f=a; |
||
78 | fb.f=b; |
||
79 | // return divFloat32(fa, fb).f; |
||
698 | cejka | 80 | } |
697 | cejka | 81 | |
542 | cejka | 82 | float __negsf2(float a) |
83 | { |
||
84 | float32 fa; |
||
85 | fa.f=a; |
||
86 | fa.parts.sign=!fa.parts.sign; |
||
87 | return fa.f; |
||
698 | cejka | 88 | } |
542 | cejka | 89 | |
90 | double __negdf2(double a) |
||
91 | { |
||
92 | float64 fa; |
||
563 | cejka | 93 | fa.d=a; |
542 | cejka | 94 | fa.parts.sign=!fa.parts.sign; |
563 | cejka | 95 | return fa.d; |
698 | cejka | 96 | } |
542 | cejka | 97 | |
647 | cejka | 98 | /* Conversion functions */ |
542 | cejka | 99 | |
697 | cejka | 100 | double __extendsfdf2(float a) |
101 | { |
||
102 | float32 fa; |
||
103 | fa.f = a; |
||
104 | return convertFloat32ToFloat64(fa).d; |
||
698 | cejka | 105 | } |
697 | cejka | 106 | |
107 | float __truncdfsf2(double a) |
||
108 | { |
||
109 | float64 da; |
||
110 | da.d = a; |
||
111 | return convertFloat64ToFloat32(da).f; |
||
112 | } |
||
698 | cejka | 113 | |
647 | cejka | 114 | /* Comparison functions */ |
542 | cejka | 115 | |
652 | cejka | 116 | /* a<b .. -1 |
117 | * a=b .. 0 |
||
118 | * a>b .. 1 |
||
119 | * */ |
||
120 | |||
660 | cejka | 121 | int __cmpsf2(float a, float b) |
652 | cejka | 122 | { |
123 | float32 fa,fb; |
||
124 | fa.f=a; |
||
125 | fb.f=b; |
||
126 | if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) { |
||
127 | return 1; /* no special constant for unordered - maybe signaled? */ |
||
128 | }; |
||
129 | |||
130 | |||
131 | if (isFloat32eq(fa,fb)) { |
||
132 | return 0; |
||
133 | }; |
||
134 | |||
135 | if (isFloat32lt(fa,fb)) { |
||
136 | return -1; |
||
137 | }; |
||
138 | return 1; |
||
139 | } |
||
140 | |||
141 | int __unordsf2(float a, float b) |
||
142 | { |
||
143 | float32 fa,fb; |
||
144 | fa.f=a; |
||
145 | fb.f=b; |
||
146 | return ((isFloat32NaN(fa))||(isFloat32NaN(fb))); |
||
698 | cejka | 147 | } |
652 | cejka | 148 | |
149 | /** |
||
150 | * @return zero, if neither argument is a NaN and are equal |
||
151 | * */ |
||
152 | int __eqsf2(float a, float b) |
||
153 | { |
||
154 | float32 fa,fb; |
||
155 | fa.f=a; |
||
156 | fb.f=b; |
||
157 | if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) { |
||
158 | /* TODO: sigNaNs*/ |
||
159 | return 1; |
||
160 | }; |
||
161 | return isFloat32eq(fa,fb)-1; |
||
698 | cejka | 162 | } |
652 | cejka | 163 | |
164 | /* strange behavior, but it was in gcc documentation */ |
||
165 | int __nesf2(float a, float b) |
||
166 | { |
||
167 | return __eqsf2(a,b); |
||
698 | cejka | 168 | } |
653 | cejka | 169 | |
170 | /* return value >= 0 if a>=b and neither is NaN */ |
||
171 | int __gesf2(float a, float b) |
||
172 | { |
||
173 | float32 fa,fb; |
||
174 | fa.f=a; |
||
175 | fb.f=b; |
||
176 | if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) { |
||
177 | /* TODO: sigNaNs*/ |
||
660 | cejka | 178 | return -1; |
653 | cejka | 179 | }; |
180 | |||
181 | if (isFloat32eq(fa,fb)) { |
||
182 | return 0; |
||
183 | }; |
||
184 | |||
185 | if (isFloat32gt(fa,fb)) { |
||
186 | return 1; |
||
187 | }; |
||
188 | |||
189 | return -1; |
||
190 | } |
||
191 | |||
192 | /** Return negative value, if a<b and neither is NaN*/ |
||
193 | int __ltsf2(float a, float b) |
||
194 | { |
||
195 | float32 fa,fb; |
||
196 | fa.f=a; |
||
197 | fb.f=b; |
||
198 | if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) { |
||
199 | /* TODO: sigNaNs*/ |
||
200 | return 1; |
||
201 | }; |
||
202 | if (isFloat32lt(fa, fb)) { |
||
203 | return -1; |
||
204 | }; |
||
205 | return 0; |
||
206 | } |
||
207 | |||
208 | /* return value <= 0 if a<=b and neither is NaN */ |
||
209 | int __lesf2(float a, float b) |
||
210 | { |
||
211 | float32 fa,fb; |
||
212 | fa.f=a; |
||
213 | fb.f=b; |
||
214 | if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) { |
||
215 | /* TODO: sigNaNs*/ |
||
216 | return 1; |
||
217 | }; |
||
218 | |||
219 | if (isFloat32eq(fa,fb)) { |
||
220 | return 0; |
||
221 | }; |
||
222 | |||
223 | if (isFloat32lt(fa,fb)) { |
||
224 | return -1; |
||
225 | }; |
||
226 | |||
227 | return 1; |
||
228 | } |
||
229 | |||
230 | /** Return positive value, if a>b and neither is NaN*/ |
||
660 | cejka | 231 | int __gtsf2(float a, float b) |
653 | cejka | 232 | { |
233 | float32 fa,fb; |
||
234 | fa.f=a; |
||
235 | fb.f=b; |
||
236 | if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) { |
||
237 | /* TODO: sigNaNs*/ |
||
660 | cejka | 238 | return -1; |
653 | cejka | 239 | }; |
240 | if (isFloat32gt(fa, fb)) { |
||
241 | return 1; |
||
242 | }; |
||
243 | return 0; |
||
244 | } |
||
245 | |||
647 | cejka | 246 | /* Other functions */ |
542 | cejka | 247 | |
698 | cejka | 248 | float __powisf2(float a, int b) |
249 | { |
||
250 | //TODO: |
||
251 | } |
||
252 | |||
253 | float __mulsc3(float a, float b, float c, float d) |
||
254 | { |
||
255 | //TODO: |
||
256 | } |
||
257 | |||
258 | float __divsc3(float a, float b, float c, float d) |
||
259 | { |
||
260 | //TODO: |
||
261 | } |
||
262 |