xref: /netbsd-src/regress/lib/libc/ieeefp/testfloat/systfloat.c (revision ce099b40997c43048fb78bd578195f81d2456523)
1*ce099b40Smartin /*	$NetBSD: systfloat.c,v 1.8 2008/04/28 20:23:04 martin Exp $	*/
289f51f80Sross 
389f51f80Sross /* This is a derivative work. */
489f51f80Sross 
589f51f80Sross /*-
689f51f80Sross  * Copyright (c) 2001 The NetBSD Foundation, Inc.
789f51f80Sross  * All rights reserved.
889f51f80Sross  *
989f51f80Sross  * This code is derived from software contributed to The NetBSD Foundation
1089f51f80Sross  * by Ross Harvey.
1189f51f80Sross  *
1289f51f80Sross  * Redistribution and use in source and binary forms, with or without
1389f51f80Sross  * modification, are permitted provided that the following conditions
1489f51f80Sross  * are met:
1589f51f80Sross  * 1. Redistributions of source code must retain the above copyright
1689f51f80Sross  *    notice, this list of conditions and the following disclaimer.
1789f51f80Sross  * 2. Redistributions in binary form must reproduce the above copyright
1889f51f80Sross  *    notice, this list of conditions and the following disclaimer in the
1989f51f80Sross  *    documentation and/or other materials provided with the distribution.
2089f51f80Sross  *
2189f51f80Sross  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2289f51f80Sross  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2389f51f80Sross  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2489f51f80Sross  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2589f51f80Sross  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2689f51f80Sross  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2789f51f80Sross  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2889f51f80Sross  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2989f51f80Sross  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3089f51f80Sross  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3189f51f80Sross  * POSSIBILITY OF SUCH DAMAGE.
3289f51f80Sross  */
33122b058aSross 
34122b058aSross /*
35122b058aSross ===============================================================================
36122b058aSross 
37122b058aSross This C source file is part of TestFloat, Release 2a, a package of programs
38122b058aSross for testing the correctness of floating-point arithmetic complying to the
39122b058aSross IEC/IEEE Standard for Floating-Point.
40122b058aSross 
41122b058aSross Written by John R. Hauser.  More information is available through the Web
42122b058aSross page `http://HTTP.CS.Berkeley.EDU/~jhauser/arithmetic/TestFloat.html'.
43122b058aSross 
44122b058aSross THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE.  Although reasonable effort
45122b058aSross has been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT
46122b058aSross TIMES RESULT IN INCORRECT BEHAVIOR.  USE OF THIS SOFTWARE IS RESTRICTED TO
47122b058aSross PERSONS AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ANY
48122b058aSross AND ALL LOSSES, COSTS, OR OTHER PROBLEMS ARISING FROM ITS USE.
49122b058aSross 
50122b058aSross Derivative works are acceptable, even for commercial purposes, so long as
51122b058aSross (1) they include prominent notice that the work is derivative, and (2) they
52122b058aSross include prominent notice akin to these four paragraphs for those parts of
53122b058aSross this code that are retained.
54122b058aSross 
55122b058aSross ===============================================================================
56122b058aSross */
57122b058aSross 
58504509aaSross #include <sys/cdefs.h>
59504509aaSross #ifndef __lint
60*ce099b40Smartin __RCSID("$NetBSD: systfloat.c,v 1.8 2008/04/28 20:23:04 martin Exp $");
61504509aaSross #endif
62504509aaSross 
63122b058aSross #include <math.h>
64504509aaSross #include <ieeefp.h>
65122b058aSross #include "milieu.h"
66122b058aSross #include "softfloat.h"
67122b058aSross #include "systfloat.h"
68504509aaSross #include "systflags.h"
69504509aaSross #include "systmodes.h"
70504509aaSross 
71ae686a7dSmatt typedef union {
72ae686a7dSmatt     float32 f32;
73ae686a7dSmatt     float f;
74ae686a7dSmatt } union32;
75ae686a7dSmatt typedef union {
76ae686a7dSmatt     float64 f64;
77ae686a7dSmatt     double d;
78ae686a7dSmatt } union64;
79ae686a7dSmatt #if defined( FLOATX80 ) && defined( LONG_DOUBLE_IS_FLOATX80 )
80ae686a7dSmatt typedef union {
81ae686a7dSmatt     floatx80 fx80;
82ae686a7dSmatt     long double ld;
83ae686a7dSmatt } unionx80;
84ae686a7dSmatt #endif
85ae686a7dSmatt #if defined( FLOAT128 ) && defined( LONG_DOUBLE_IS_FLOAT128 )
86ae686a7dSmatt typedef union {
87ae686a7dSmatt     float128 f128;
88ae686a7dSmatt     long double ld;
89ae686a7dSmatt } union128;
90ae686a7dSmatt #endif
91ae686a7dSmatt 
92504509aaSross fp_except
syst_float_flags_clear(void)93504509aaSross syst_float_flags_clear(void)
94504509aaSross {
95c51692d1Sross     return fpsetsticky(0)
96c51692d1Sross 	& (FP_X_IMP | FP_X_UFL | FP_X_OFL | FP_X_DZ | FP_X_INV);
97504509aaSross }
98504509aaSross 
99504509aaSross void
syst_float_set_rounding_mode(fp_rnd direction)100504509aaSross syst_float_set_rounding_mode(fp_rnd direction)
101504509aaSross {
102504509aaSross     fpsetround(direction);
103504509aaSross     fpsetmask(0);
104504509aaSross }
105122b058aSross 
syst_int32_to_float32(int32 a)106122b058aSross float32 syst_int32_to_float32( int32 a )
107122b058aSross {
108ae686a7dSmatt     const union32 uz = { .f = a };
109122b058aSross 
110ae686a7dSmatt     return uz.f32;
111122b058aSross 
112122b058aSross }
113122b058aSross 
syst_int32_to_float64(int32 a)114122b058aSross float64 syst_int32_to_float64( int32 a )
115122b058aSross {
116ae686a7dSmatt     const union64 uz = { .d = a };
117122b058aSross 
118ae686a7dSmatt     return uz.f64;
119122b058aSross 
120122b058aSross }
121122b058aSross 
122122b058aSross #if defined( FLOATX80 ) && defined( LONG_DOUBLE_IS_FLOATX80 )
123122b058aSross 
syst_int32_to_floatx80(int32 a)124122b058aSross floatx80 syst_int32_to_floatx80( int32 a )
125122b058aSross {
126ae686a7dSmatt     const unionx80 uz = { .ld = a };
127122b058aSross 
128ae686a7dSmatt     return uz.fx80;
129122b058aSross 
130122b058aSross }
131122b058aSross 
132122b058aSross #endif
133122b058aSross 
134122b058aSross #if defined( FLOAT128 ) && defined( LONG_DOUBLE_IS_FLOAT128 )
135122b058aSross 
syst_int32_to_float128(int32 a)136122b058aSross float128 syst_int32_to_float128( int32 a )
137122b058aSross {
138ae686a7dSmatt     const union128 uz = { .ld = a };
139122b058aSross 
140ae686a7dSmatt     return uz.f128;
141122b058aSross 
142122b058aSross }
143122b058aSross 
144122b058aSross #endif
145122b058aSross 
146122b058aSross #ifdef BITS64
147122b058aSross 
syst_int64_to_float32(int64 a)148122b058aSross float32 syst_int64_to_float32( int64 a )
149122b058aSross {
150ae686a7dSmatt     const union32 uz = { .f = a };
151122b058aSross 
152ae686a7dSmatt     return uz.f32;
153122b058aSross }
154122b058aSross 
syst_int64_to_float64(int64 a)155122b058aSross float64 syst_int64_to_float64( int64 a )
156122b058aSross {
157ae686a7dSmatt     const union64 uz = { .d = a };
158122b058aSross 
159ae686a7dSmatt     return uz.f64;
160122b058aSross }
161122b058aSross 
162122b058aSross #if defined( FLOATX80 ) && defined( LONG_DOUBLE_IS_FLOATX80 )
163122b058aSross 
syst_int64_to_floatx80(int64 a)164122b058aSross floatx80 syst_int64_to_floatx80( int64 a )
165122b058aSross {
166ae686a7dSmatt     const unionx80 uz = { .ld = a };
167122b058aSross 
168ae686a7dSmatt     return uz.fx80;
169122b058aSross }
170122b058aSross 
171122b058aSross #endif
172122b058aSross 
173122b058aSross #if defined( FLOAT128 ) && defined( LONG_DOUBLE_IS_FLOAT128 )
174122b058aSross 
syst_int64_to_float128(int64 a)175122b058aSross float128 syst_int64_to_float128( int64 a )
176122b058aSross {
177ae686a7dSmatt     const union128 uz = { .ld = a };
178122b058aSross 
179ae686a7dSmatt     return uz.f128;
180122b058aSross }
181122b058aSross 
182122b058aSross #endif
183122b058aSross 
184122b058aSross #endif
185122b058aSross 
syst_float32_to_int32_round_to_zero(float32 a)186122b058aSross int32 syst_float32_to_int32_round_to_zero( float32 a )
187122b058aSross {
188ae686a7dSmatt     const union32 uz = { .f32 = a };
189122b058aSross 
190ae686a7dSmatt     return uz.f;
191122b058aSross 
192122b058aSross }
193122b058aSross 
194122b058aSross #ifdef BITS64
195122b058aSross 
syst_float32_to_int64_round_to_zero(float32 a)196122b058aSross int64 syst_float32_to_int64_round_to_zero( float32 a )
197122b058aSross {
198ae686a7dSmatt     const union32 uz = { .f32 = a };
199122b058aSross 
200ae686a7dSmatt     return uz.f;
201122b058aSross }
202122b058aSross 
203122b058aSross #endif
204122b058aSross 
syst_float32_to_float64(float32 a)205122b058aSross float64 syst_float32_to_float64( float32 a )
206122b058aSross {
207ae686a7dSmatt     const union32 ua = { .f32 = a };
208ae686a7dSmatt     union64 uz;
209122b058aSross 
210ae686a7dSmatt     uz.d = ua.f;
211ae686a7dSmatt     return uz.f64;
212122b058aSross 
213122b058aSross }
214122b058aSross 
215122b058aSross #if defined( FLOATX80 ) && defined( LONG_DOUBLE_IS_FLOATX80 )
216122b058aSross 
syst_float32_to_floatx80(float32 a)217122b058aSross floatx80 syst_float32_to_floatx80( float32 a )
218122b058aSross {
219ae686a7dSmatt     const union32 ua = { .f32 = a };
220ae686a7dSmatt     unionx80 uz;
221122b058aSross 
222ae686a7dSmatt     uz.ld = ua.f;
223ae686a7dSmatt     return uz.fx80;
224122b058aSross }
225122b058aSross 
226122b058aSross #endif
227122b058aSross 
228122b058aSross #if defined( FLOAT128 ) && defined( LONG_DOUBLE_IS_FLOAT128 )
229122b058aSross 
syst_float32_to_float128(float32 a)230122b058aSross float128 syst_float32_to_float128( float32 a )
231122b058aSross {
232ae686a7dSmatt     const union32 ua = { .f32 = a };
233ae686a7dSmatt     union128 ub;
234122b058aSross 
235ae686a7dSmatt     ub.ld = ua.f;
236ae686a7dSmatt     return ub.f128;
237122b058aSross }
238122b058aSross 
239122b058aSross #endif
240122b058aSross 
syst_float32_add(float32 a,float32 b)241122b058aSross float32 syst_float32_add( float32 a, float32 b )
242122b058aSross {
243ae686a7dSmatt     const union32 ua = { .f32 = a }, ub = { .f32 = b };
244ae686a7dSmatt     union32 uz;
245122b058aSross 
246ae686a7dSmatt     uz.f = ua.f + ub.f;
247ae686a7dSmatt     return uz.f32;
248122b058aSross }
249122b058aSross 
syst_float32_sub(float32 a,float32 b)250122b058aSross float32 syst_float32_sub( float32 a, float32 b )
251122b058aSross {
252ae686a7dSmatt     const union32 ua = { .f32 = a }, ub = { .f32 = b };
253ae686a7dSmatt     union32 uz;
254122b058aSross 
255ae686a7dSmatt     uz.f = ua.f - ub.f;
256ae686a7dSmatt     return uz.f32;
257122b058aSross }
258122b058aSross 
syst_float32_mul(float32 a,float32 b)259122b058aSross float32 syst_float32_mul( float32 a, float32 b )
260122b058aSross {
261ae686a7dSmatt     const union32 ua = { .f32 = a }, ub = { .f32 = b };
262ae686a7dSmatt     union32 uz;
263122b058aSross 
264ae686a7dSmatt     uz.f = ua.f * ub.f;
265ae686a7dSmatt     return uz.f32;
266122b058aSross }
267122b058aSross 
syst_float32_div(float32 a,float32 b)268122b058aSross float32 syst_float32_div( float32 a, float32 b )
269122b058aSross {
270ae686a7dSmatt     const union32 ua = { .f32 = a }, ub = { .f32 = b };
271ae686a7dSmatt     union32 uz;
272122b058aSross 
273ae686a7dSmatt     uz.f = ua.f / ub.f;
274ae686a7dSmatt     return uz.f32;
275122b058aSross }
276122b058aSross 
syst_float32_eq(float32 a,float32 b)277122b058aSross flag syst_float32_eq( float32 a, float32 b )
278122b058aSross {
279ae686a7dSmatt     const union32 ua = { .f32 = a }, ub = { .f32 = b };
280122b058aSross 
281ae686a7dSmatt     return ua.f == ub.f;
282122b058aSross }
283122b058aSross 
syst_float32_le(float32 a,float32 b)284122b058aSross flag syst_float32_le( float32 a, float32 b )
285122b058aSross {
286ae686a7dSmatt     const union32 ua = { .f32 = a }, ub = { .f32 = b };
287122b058aSross 
288ae686a7dSmatt     return ua.f <= ub.f;
289122b058aSross }
290122b058aSross 
syst_float32_lt(float32 a,float32 b)291122b058aSross flag syst_float32_lt( float32 a, float32 b )
292122b058aSross {
293ae686a7dSmatt     const union32 ua = { .f32 = a }, ub = { .f32 = b };
294122b058aSross 
295ae686a7dSmatt     return ua.f < ub.f;
296122b058aSross }
297122b058aSross 
syst_float64_to_int32_round_to_zero(float64 a)298122b058aSross int32 syst_float64_to_int32_round_to_zero( float64 a )
299122b058aSross {
300ae686a7dSmatt     const union64 uz = { .f64 = a };
301122b058aSross 
302ae686a7dSmatt     return uz.d;
303122b058aSross }
304122b058aSross 
305122b058aSross #ifdef BITS64
306122b058aSross 
syst_float64_to_int64_round_to_zero(float64 a)307122b058aSross int64 syst_float64_to_int64_round_to_zero( float64 a )
308122b058aSross {
309ae686a7dSmatt     const union64 uz = { .f64 = a };
310122b058aSross 
311ae686a7dSmatt     return uz.d;
312122b058aSross }
313122b058aSross 
314122b058aSross #endif
315122b058aSross 
syst_float64_to_float32(float64 a)316122b058aSross float32 syst_float64_to_float32( float64 a )
317122b058aSross {
318ae686a7dSmatt     const union64 ua = { .f64 = a };
319ae686a7dSmatt     union32 uz;
320122b058aSross 
321ae686a7dSmatt     uz.f = ua.d;
322ae686a7dSmatt     return uz.f32;
323122b058aSross }
324122b058aSross 
325122b058aSross #if defined( FLOATX80 ) && defined( LONG_DOUBLE_IS_FLOATX80 )
326122b058aSross 
syst_float64_to_floatx80(float64 a)327122b058aSross floatx80 syst_float64_to_floatx80( float64 a )
328122b058aSross {
329ae686a7dSmatt     const union64 ua = { .f64 = a };
330ae686a7dSmatt     unionx80 u;
331122b058aSross 
332ae686a7dSmatt     u.ld = ua.d;
333ae686a7dSmatt     return u.fx80;
334122b058aSross }
335122b058aSross 
336122b058aSross #endif
337122b058aSross 
338122b058aSross #if defined( FLOAT128 ) && defined( LONG_DOUBLE_IS_FLOAT128 )
339122b058aSross 
syst_float64_to_float128(float64 a)340122b058aSross float128 syst_float64_to_float128( float64 a )
341122b058aSross {
342ae686a7dSmatt     const union64 ua = { .f64 = a };
343ae686a7dSmatt     union128 uz;
344122b058aSross 
345ae686a7dSmatt     uz.ld = ua.d;
346ae686a7dSmatt     return uz.f128;
347122b058aSross }
348122b058aSross 
349122b058aSross #endif
350122b058aSross 
syst_float64_add(float64 a,float64 b)351122b058aSross float64 syst_float64_add( float64 a, float64 b )
352122b058aSross {
353ae686a7dSmatt     const union64 ua = { .f64 = a }, ub = { .f64 = b };
354ae686a7dSmatt     union64 uz;
355122b058aSross 
356ae686a7dSmatt     uz.d = ua.d + ub.d;
357ae686a7dSmatt     return uz.f64;
358122b058aSross }
359122b058aSross 
syst_float64_sub(float64 a,float64 b)360122b058aSross float64 syst_float64_sub( float64 a, float64 b )
361122b058aSross {
362ae686a7dSmatt     const union64 ua = { .f64 = a }, ub = { .f64 = b };
363ae686a7dSmatt     union64 uz;
364122b058aSross 
365ae686a7dSmatt     uz.d = ua.d - ub.d;
366ae686a7dSmatt     return uz.f64;
367122b058aSross }
368122b058aSross 
syst_float64_mul(float64 a,float64 b)369122b058aSross float64 syst_float64_mul( float64 a, float64 b )
370122b058aSross {
371ae686a7dSmatt     const union64 ua = { .f64 = a }, ub = { .f64 = b };
372ae686a7dSmatt     union64 uz;
373122b058aSross 
374ae686a7dSmatt     uz.d = ua.d * ub.d;
375ae686a7dSmatt     return uz.f64;
376122b058aSross }
377122b058aSross 
syst_float64_div(float64 a,float64 b)378122b058aSross float64 syst_float64_div( float64 a, float64 b )
379122b058aSross {
380ae686a7dSmatt     const union64 ua = { .f64 = a }, ub = { .f64 = b };
381ae686a7dSmatt     union64 uz;
382122b058aSross 
383ae686a7dSmatt     uz.d = ua.d / ub.d;
384ae686a7dSmatt     return uz.f64;
385122b058aSross }
386122b058aSross 
syst_float64_sqrt(float64 a)387122b058aSross float64 syst_float64_sqrt( float64 a )
388122b058aSross {
389ae686a7dSmatt     const union64 ua = { .f64 = a };
390ae686a7dSmatt     union64 uz;
391122b058aSross 
392ae686a7dSmatt     uz.d = sqrt(ua.d);
393ae686a7dSmatt     return uz.f64;
394122b058aSross }
395122b058aSross 
syst_float64_eq(float64 a,float64 b)396122b058aSross flag syst_float64_eq( float64 a, float64 b )
397122b058aSross {
398ae686a7dSmatt     const union64 ua = { .f64 = a }, ub = { .f64 = b };
399122b058aSross 
400ae686a7dSmatt     return ua.d == ub.d;
401122b058aSross }
402122b058aSross 
syst_float64_le(float64 a,float64 b)403122b058aSross flag syst_float64_le( float64 a, float64 b )
404122b058aSross {
405ae686a7dSmatt     const union64 ua = { .f64 = a }, ub = { .f64 = b };
406122b058aSross 
407ae686a7dSmatt     return ua.d <= ub.d;
408122b058aSross }
409122b058aSross 
syst_float64_lt(float64 a,float64 b)410122b058aSross flag syst_float64_lt( float64 a, float64 b )
411122b058aSross {
412ae686a7dSmatt     const union64 ua = { .f64 = a }, ub = { .f64 = b };
413122b058aSross 
414ae686a7dSmatt     return ua.d < ub.d;
415122b058aSross }
416122b058aSross 
417122b058aSross #if defined( FLOATX80 ) && defined( LONG_DOUBLE_IS_FLOATX80 )
418122b058aSross 
syst_floatx80_to_int32_round_to_zero(floatx80 a)419122b058aSross int32 syst_floatx80_to_int32_round_to_zero( floatx80 a )
420122b058aSross {
421ae686a7dSmatt     const unionx80 uz = { .fx80 = a };
422122b058aSross 
423ae686a7dSmatt     return uz.ld;
424122b058aSross }
425122b058aSross 
426122b058aSross #ifdef BITS64
427122b058aSross 
syst_floatx80_to_int64_round_to_zero(floatx80 a)428122b058aSross int64 syst_floatx80_to_int64_round_to_zero( floatx80 a )
429122b058aSross {
430ae686a7dSmatt     const unionx80 uz = { .fx80 = a };
431122b058aSross 
432ae686a7dSmatt     return uz.ld;
433122b058aSross }
434122b058aSross 
435122b058aSross #endif
436122b058aSross 
syst_floatx80_to_float32(floatx80 a)437122b058aSross float32 syst_floatx80_to_float32( floatx80 a )
438122b058aSross {
439ae686a7dSmatt     const unionx80 ua = { .fx80 = a };
440ae686a7dSmatt     union32 uz;
441122b058aSross 
442ae686a7dSmatt     uz.f = ua.ld;
443ae686a7dSmatt     return uz.f32;
444122b058aSross }
445122b058aSross 
syst_floatx80_to_float64(floatx80 a)446122b058aSross float64 syst_floatx80_to_float64( floatx80 a )
447122b058aSross {
448ae686a7dSmatt     const unionx80 ua = { .fx80 = a };
449ae686a7dSmatt     union64 uz;
450122b058aSross 
451ae686a7dSmatt     uz.d = ua.ld;
452ae686a7dSmatt     return uz.f64;
453122b058aSross }
454122b058aSross 
syst_floatx80_add(floatx80 a,floatx80 b)455122b058aSross floatx80 syst_floatx80_add( floatx80 a, floatx80 b )
456122b058aSross {
457ae686a7dSmatt     const unionx80 ua = { .fx80 = a }, ub = { .fx80 = b };
458ae686a7dSmatt     unionx80 uz;
459122b058aSross 
460ae686a7dSmatt     uz.ld = ua.ld + ub.ld;
461ae686a7dSmatt     return uz.fx80;
462122b058aSross }
463122b058aSross 
syst_floatx80_sub(floatx80 a,floatx80 b)464122b058aSross floatx80 syst_floatx80_sub( floatx80 a, floatx80 b )
465122b058aSross {
466ae686a7dSmatt     const unionx80 ua = { .fx80 = a }, ub = { .fx80 = b };
467ae686a7dSmatt     unionx80 uz;
468122b058aSross 
469ae686a7dSmatt     uz.ld = ua.ld - ub.ld;
470ae686a7dSmatt     return uz.fx80;
471122b058aSross }
472122b058aSross 
syst_floatx80_mul(floatx80 a,floatx80 b)473122b058aSross floatx80 syst_floatx80_mul( floatx80 a, floatx80 b )
474122b058aSross {
475ae686a7dSmatt     const unionx80 ua = { .fx80 = a }, ub = { .fx80 = b };
476ae686a7dSmatt     unionx80 uz;
477122b058aSross 
478ae686a7dSmatt     uz.ld = ua.ld * ub.ld;
479ae686a7dSmatt     return uz.fx80;
480122b058aSross }
481122b058aSross 
syst_floatx80_div(floatx80 a,floatx80 b)482122b058aSross floatx80 syst_floatx80_div( floatx80 a, floatx80 b )
483122b058aSross {
484ae686a7dSmatt     const unionx80 ua = { .fx80 = a }, ub = { .fx80 = b };
485ae686a7dSmatt     unionx80 uz;
486122b058aSross 
487ae686a7dSmatt     uz.ld = ua.ld / ub.ld;
488ae686a7dSmatt     return uz.fx80;
489122b058aSross }
490122b058aSross 
syst_floatx80_eq(floatx80 a,floatx80 b)491122b058aSross flag syst_floatx80_eq( floatx80 a, floatx80 b )
492122b058aSross {
493ae686a7dSmatt     const unionx80 ua = { .fx80 = a }, ub = { .fx80 = b };
494122b058aSross 
495ae686a7dSmatt     return ua.ld == ub.ld;
496122b058aSross }
497122b058aSross 
syst_floatx80_le(floatx80 a,floatx80 b)498122b058aSross flag syst_floatx80_le( floatx80 a, floatx80 b )
499122b058aSross {
500ae686a7dSmatt     const unionx80 ua = { .fx80 = a }, ub = { .fx80 = b };
501122b058aSross 
502ae686a7dSmatt     return ua.ld <= ub.ld;
503122b058aSross }
504122b058aSross 
syst_floatx80_lt(floatx80 a,floatx80 b)505122b058aSross flag syst_floatx80_lt( floatx80 a, floatx80 b )
506122b058aSross {
507ae686a7dSmatt     const unionx80 ua = { .fx80 = a }, ub = { .fx80 = b };
508122b058aSross 
509ae686a7dSmatt     return ua.ld < ub.ld;
510122b058aSross }
511122b058aSross 
512122b058aSross #endif
513122b058aSross 
514122b058aSross #if defined( FLOAT128 ) && defined( LONG_DOUBLE_IS_FLOAT128 )
515122b058aSross 
syst_float128_to_int32_round_to_zero(float128 a)516122b058aSross int32 syst_float128_to_int32_round_to_zero( float128 a )
517122b058aSross {
518ae686a7dSmatt     const union128 ua = { .f128 = a };
519122b058aSross 
520ae686a7dSmatt     return ua.ld;
521122b058aSross }
522122b058aSross 
523122b058aSross #ifdef BITS64
524122b058aSross 
syst_float128_to_int64_round_to_zero(float128 a)525122b058aSross int64 syst_float128_to_int64_round_to_zero( float128 a )
526122b058aSross {
527ae686a7dSmatt     const union128 ua = { .f128 = a };
528122b058aSross 
529ae686a7dSmatt     return ua.ld;
530122b058aSross }
531122b058aSross 
532122b058aSross #endif
533122b058aSross 
syst_float128_to_float32(float128 a)534122b058aSross float32 syst_float128_to_float32( float128 a )
535122b058aSross {
536ae686a7dSmatt     const union128 ua = { .f128 = a };
537ae686a7dSmatt     union32 uz;
538122b058aSross 
539ae686a7dSmatt     uz.f = ua.ld;
540ae686a7dSmatt     return uz.f32;
541122b058aSross 
542122b058aSross }
543122b058aSross 
syst_float128_to_float64(float128 a)544122b058aSross float64 syst_float128_to_float64( float128 a )
545122b058aSross {
546ae686a7dSmatt     const union128 ua = { .f128 = a };
547ae686a7dSmatt     union64 uz;
548122b058aSross 
549ae686a7dSmatt     uz.d = ua.ld;
550ae686a7dSmatt     return uz.f64;
551122b058aSross }
552122b058aSross 
syst_float128_add(float128 a,float128 b)553122b058aSross float128 syst_float128_add( float128 a, float128 b )
554122b058aSross {
555ae686a7dSmatt     const union128 ua = { .f128 = a }, ub = { .f128 = b };
556ae686a7dSmatt     union128 uz;
557122b058aSross 
558ae686a7dSmatt     uz.ld = ua.ld + ub.ld;
559ae686a7dSmatt     return uz.f128;
560122b058aSross 
561122b058aSross }
562122b058aSross 
syst_float128_sub(float128 a,float128 b)563122b058aSross float128 syst_float128_sub( float128 a, float128 b )
564122b058aSross {
565ae686a7dSmatt     const union128 ua = { .f128 = a }, ub = { .f128 = b };
566ae686a7dSmatt     union128 uz;
567122b058aSross 
568ae686a7dSmatt     uz.ld = ua.ld - ub.ld;
569ae686a7dSmatt     return uz.f128;
570122b058aSross }
571122b058aSross 
syst_float128_mul(float128 a,float128 b)572122b058aSross float128 syst_float128_mul( float128 a, float128 b )
573122b058aSross {
574ae686a7dSmatt     const union128 ua = { .f128 = a }, ub = { .f128 = b };
575ae686a7dSmatt     union128 uz;
576122b058aSross 
577ae686a7dSmatt     uz.ld = ua.ld * ub.ld;
578ae686a7dSmatt     return uz.f128;
579122b058aSross }
580122b058aSross 
syst_float128_div(float128 a,float128 b)581122b058aSross float128 syst_float128_div( float128 a, float128 b )
582122b058aSross {
583ae686a7dSmatt     const union128 ua = { .f128 = a }, ub = { .f128 = b };
584ae686a7dSmatt     union128 uz;
585122b058aSross 
586ae686a7dSmatt     uz.ld = ua.ld / ub.ld;
587ae686a7dSmatt     return uz.f128;
588122b058aSross }
589122b058aSross 
syst_float128_eq(float128 a,float128 b)590122b058aSross flag syst_float128_eq( float128 a, float128 b )
591122b058aSross {
592ae686a7dSmatt     const union128 ua = { .f128 = a }, ub = { .f128 = b };
593122b058aSross 
594ae686a7dSmatt     return ua.ld == ub.ld;
595122b058aSross }
596122b058aSross 
syst_float128_le(float128 a,float128 b)597122b058aSross flag syst_float128_le( float128 a, float128 b )
598122b058aSross {
599ae686a7dSmatt     const union128 ua = { .f128 = a }, ub = { .f128 = b };
600122b058aSross 
601ae686a7dSmatt     return ua.ld <= ub.ld;
602122b058aSross }
603122b058aSross 
syst_float128_lt(float128 a,float128 b)604122b058aSross flag syst_float128_lt( float128 a, float128 b )
605122b058aSross {
606ae686a7dSmatt     const union128 ua = { .f128 = a }, ub = { .f128 = b };
607122b058aSross 
608ae686a7dSmatt     return ua.ld < ub.ld;
609122b058aSross }
610122b058aSross 
611122b058aSross #endif
612