No empty .Rs/.Re
[netbsd-mini2440.git] / regress / lib / libc / ieeefp / testfloat / writeHex.c
blob1022ea62503597302d878ee7dcb6e15ebf041661
1 /* $NetBSD: writeHex.c,v 1.4 2002/02/21 07:38:16 itojun Exp $ */
3 /* This is a derivative work. */
5 /*-
6 * Copyright (c) 2001 The NetBSD Foundation, Inc.
7 * All rights reserved.
9 * This code is derived from software contributed to The NetBSD Foundation
10 * by Ross Harvey.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
21 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
35 ===============================================================================
37 This C source file is part of TestFloat, Release 2a, a package of programs
38 for testing the correctness of floating-point arithmetic complying to the
39 IEC/IEEE Standard for Floating-Point.
41 Written by John R. Hauser. More information is available through the Web
42 page `http://HTTP.CS.Berkeley.EDU/~jhauser/arithmetic/TestFloat.html'.
44 THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort
45 has been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT
46 TIMES RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO
47 PERSONS AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ANY
48 AND ALL LOSSES, COSTS, OR OTHER PROBLEMS ARISING FROM ITS USE.
50 Derivative works are acceptable, even for commercial purposes, so long as
51 (1) they include prominent notice that the work is derivative, and (2) they
52 include prominent notice akin to these four paragraphs for those parts of
53 this code that are retained.
55 ===============================================================================
58 #include <stdio.h>
59 #include "milieu.h"
60 #include "softfloat.h"
61 #include "writeHex.h"
63 void writeHex_flag( flag a, FILE *stream )
66 fputc( a ? '1' : '0', stream );
70 static void writeHex_bits8( bits8 a, FILE *stream )
72 int digit;
74 digit = ( a>>4 ) & 0xF;
75 if ( 9 < digit ) digit += 'A' - ( '0' + 10 );
76 fputc( '0' + digit, stream );
77 digit = a & 0xF;
78 if ( 9 < digit ) digit += 'A' - ( '0' + 10 );
79 fputc( '0' + digit, stream );
83 static void writeHex_bits12( int16 a, FILE *stream )
85 int digit;
87 digit = ( a>>8 ) & 0xF;
88 if ( 9 < digit ) digit += 'A' - ( '0' + 10 );
89 fputc( '0' + digit, stream );
90 digit = ( a>>4 ) & 0xF;
91 if ( 9 < digit ) digit += 'A' - ( '0' + 10 );
92 fputc( '0' + digit, stream );
93 digit = a & 0xF;
94 if ( 9 < digit ) digit += 'A' - ( '0' + 10 );
95 fputc( '0' + digit, stream );
99 static void writeHex_bits16( bits16 a, FILE *stream )
101 int digit;
103 digit = ( a>>12 ) & 0xF;
104 if ( 9 < digit ) digit += 'A' - ( '0' + 10 );
105 fputc( '0' + digit, stream );
106 digit = ( a>>8 ) & 0xF;
107 if ( 9 < digit ) digit += 'A' - ( '0' + 10 );
108 fputc( '0' + digit, stream );
109 digit = ( a>>4 ) & 0xF;
110 if ( 9 < digit ) digit += 'A' - ( '0' + 10 );
111 fputc( '0' + digit, stream );
112 digit = a & 0xF;
113 if ( 9 < digit ) digit += 'A' - ( '0' + 10 );
114 fputc( '0' + digit, stream );
118 void writeHex_bits32( bits32 a, FILE *stream )
121 writeHex_bits16( a>>16, stream );
122 writeHex_bits16( a, stream );
126 #ifdef BITS64
128 void writeHex_bits64( bits64 a, FILE *stream )
131 writeHex_bits32( a>>32, stream );
132 writeHex_bits32( a, stream );
136 #endif
138 void writeHex_float32( float32 a, FILE *stream )
141 fputc( ( ( (sbits32) a ) < 0 ) ? '8' : '0', stream );
142 writeHex_bits8( a>>23, stream );
143 fputc( '.', stream );
144 writeHex_bits8( ( a>>16 ) & 0x7F, stream );
145 writeHex_bits16( a, stream );
149 #ifdef BITS64
151 void writeHex_float64( float64 a, FILE *stream )
154 writeHex_bits12( a>>52, stream );
155 fputc( '.', stream );
156 writeHex_bits12( a>>40, stream );
157 writeHex_bits8( a>>32, stream );
158 writeHex_bits32( a, stream );
162 #else
164 void writeHex_float64( float64 a, FILE *stream )
167 writeHex_bits12( a.high>>20, stream );
168 fputc( '.', stream );
169 writeHex_bits12( a.high>>8, stream );
170 writeHex_bits8( a.high, stream );
171 writeHex_bits32( a.low, stream );
175 #endif
177 #ifdef FLOATX80
179 void writeHex_floatx80( floatx80 a, FILE *stream )
182 writeHex_bits16( a.high, stream );
183 fputc( '.', stream );
184 writeHex_bits64( a.low, stream );
188 #endif
190 #ifdef FLOAT128
192 void writeHex_float128( float128 a, FILE *stream )
195 writeHex_bits16( a.high>>48, stream );
196 fputc( '.', stream );
197 writeHex_bits16( a.high>>32, stream );
198 writeHex_bits32( a.high, stream );
199 writeHex_bits64( a.low, stream );
203 #endif
205 void writeHex_float_flags( uint8 flags, FILE *stream )
208 fputc( flags & float_flag_invalid ? 'v' : '.', stream );
209 fputc( flags & float_flag_divbyzero ? 'z' : '.', stream );
210 fputc( flags & float_flag_overflow ? 'o' : '.', stream );
211 fputc( flags & float_flag_underflow ? 'u' : '.', stream );
212 fputc( flags & float_flag_inexact ? 'x' : '.', stream );