Debian Codegraph @

external/gsl/gsl_ieee-utils__make_rep.c

raw symbols SCIP
1 /* ieee-utils/make_rep.c
2 *
3 * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20 #include "gsl__config.h"cxx . . $ `<file>/external/gsl/gsl__config.h`/
21 #include "gsl_ieee_utils.h"cxx . . $ `<file>/external/gsl/gsl_ieee_utils.h`/
22
23 #include "gsl_ieee-utils__endian.c"cxx . . $ `<file>/external/gsl/gsl_ieee-utils__endian.c`/
24 #include "gsl_ieee-utils__standardize.c"cxx . . $ `<file>/external/gsl/gsl_ieee-utils__standardize.c`/
25
26 static void sprint_nybblecxx . . $ sprint_nybble(577809987ad7a468).(int i, char *s) ;
27 static void sprint_bytecxx . . $ sprint_byte(577809987ad7a468).(int i, char *s) ;
28 static int determine_ieee_typecxx . . $ determine_ieee_type(2326284602b0bb2d). (int non_zero, int exponent, int max_exponent);
29
30
31 /* For the IEEE float format the bits are found from the following
32 masks,
33
34 sign = 0x80000000
35 exponent = 0x7f800000
36 mantisssa = 0x007fffff
37
38 For the IEEE double format the masks are,
39
40 sign = 0x8000000000000000
41 exponent = 0x7ff0000000000000
42 mantissa = 0x000fffffffffffff
43
44 */
45
46 void
47 gsl_ieee_float_to_repcxx . . $ gsl_ieee_float_to_rep(2307f7fb15caa9b4). (const float * x, gsl_ieee_float_repcxx . . $ gsl_ieee_float_rep# * r)
48 {
49 int e, non_zero;
50
51 unioncxx . . $ gsl_ieee_float_to_rep(2307f7fb15caa9b4).$anonymous_type_0# {
52 float fcxx . . $ gsl_ieee_float_to_rep(2307f7fb15caa9b4).$anonymous_type_0#f.;
53 structcxx . . $ gsl_ieee_float_to_rep(2307f7fb15caa9b4).$anonymous_type_0#$anonymous_type_1# {
54 unsigned char bytecxx . . $ gsl_ieee_float_to_rep(2307f7fb15caa9b4).$anonymous_type_0#$anonymous_type_1#byte.[4] ;
55 } ieeecxx . . $ gsl_ieee_float_to_rep(2307f7fb15caa9b4).$anonymous_type_0#ieee. ;
56 } u;
57
58 u.fcxx . . $ gsl_ieee_float_to_rep(2307f7fb15caa9b4).$anonymous_type_0#f. = *x ;
59
60 if (little_endian_pcxx . . $ little_endian_p(b126dc7c1de90089).())
61 make_float_bigendiancxx . . $ make_float_bigendian(e6881f009d13a851).(&(u.fcxx . . $ gsl_ieee_float_to_rep(2307f7fb15caa9b4).$anonymous_type_0#f.)) ;
62
63 /* note that r->sign is signed, u.ieee.byte is unsigned */
64
65 if (u.ieeecxx . . $ gsl_ieee_float_to_rep(2307f7fb15caa9b4).$anonymous_type_0#ieee..bytecxx . . $ gsl_ieee_float_to_rep(2307f7fb15caa9b4).$anonymous_type_0#$anonymous_type_1#byte.[3]>>7)
66 {
67 r->signcxx . . $ $anonymous_type_5ee4a8f360dc24ad_1#sign. = 1 ;
68 }
69 else
70 {
71 r->signcxx . . $ $anonymous_type_5ee4a8f360dc24ad_1#sign. = 0 ;
72 }
73
74 e = (u.ieeecxx . . $ gsl_ieee_float_to_rep(2307f7fb15caa9b4).$anonymous_type_0#ieee..bytecxx . . $ gsl_ieee_float_to_rep(2307f7fb15caa9b4).$anonymous_type_0#$anonymous_type_1#byte.[3] & 0x7f) << 1 | (u.ieeecxx . . $ gsl_ieee_float_to_rep(2307f7fb15caa9b4).$anonymous_type_0#ieee..bytecxx . . $ gsl_ieee_float_to_rep(2307f7fb15caa9b4).$anonymous_type_0#$anonymous_type_1#byte.[2] & 0x80)>>7 ;
75
76 r->exponentcxx . . $ $anonymous_type_5ee4a8f360dc24ad_1#exponent. = e - 127 ;
77
78 sprint_bytecxx . . $ sprint_byte(577809987ad7a468).((u.ieeecxx . . $ gsl_ieee_float_to_rep(2307f7fb15caa9b4).$anonymous_type_0#ieee..bytecxx . . $ gsl_ieee_float_to_rep(2307f7fb15caa9b4).$anonymous_type_0#$anonymous_type_1#byte.[2] & 0x7f) << 1,r->mantissacxx . . $ $anonymous_type_5ee4a8f360dc24ad_1#mantissa.) ;
79 sprint_bytecxx . . $ sprint_byte(577809987ad7a468).(u.ieeecxx . . $ gsl_ieee_float_to_rep(2307f7fb15caa9b4).$anonymous_type_0#ieee..bytecxx . . $ gsl_ieee_float_to_rep(2307f7fb15caa9b4).$anonymous_type_0#$anonymous_type_1#byte.[1],r->mantissacxx . . $ $anonymous_type_5ee4a8f360dc24ad_1#mantissa. + 7) ;
80 sprint_bytecxx . . $ sprint_byte(577809987ad7a468).(u.ieeecxx . . $ gsl_ieee_float_to_rep(2307f7fb15caa9b4).$anonymous_type_0#ieee..bytecxx . . $ gsl_ieee_float_to_rep(2307f7fb15caa9b4).$anonymous_type_0#$anonymous_type_1#byte.[0],r->mantissacxx . . $ $anonymous_type_5ee4a8f360dc24ad_1#mantissa. + 15) ;
81
82 r->mantissacxx . . $ $anonymous_type_5ee4a8f360dc24ad_1#mantissa.[23] = '\0' ;
83
84 non_zero = u.ieeecxx . . $ gsl_ieee_float_to_rep(2307f7fb15caa9b4).$anonymous_type_0#ieee..bytecxx . . $ gsl_ieee_float_to_rep(2307f7fb15caa9b4).$anonymous_type_0#$anonymous_type_1#byte.[0] || u.ieeecxx . . $ gsl_ieee_float_to_rep(2307f7fb15caa9b4).$anonymous_type_0#ieee..bytecxx . . $ gsl_ieee_float_to_rep(2307f7fb15caa9b4).$anonymous_type_0#$anonymous_type_1#byte.[1] || (u.ieeecxx . . $ gsl_ieee_float_to_rep(2307f7fb15caa9b4).$anonymous_type_0#ieee..bytecxx . . $ gsl_ieee_float_to_rep(2307f7fb15caa9b4).$anonymous_type_0#$anonymous_type_1#byte.[2] & 0x7f);
85
86 r->typecxx . . $ $anonymous_type_5ee4a8f360dc24ad_1#type. = determine_ieee_typecxx . . $ determine_ieee_type(2326284602b0bb2d). (non_zero, e, 255) ;
87 }
88
89 void
90 gsl_ieee_double_to_repcxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b). (const double * x, gsl_ieee_double_repcxx . . $ gsl_ieee_double_rep# * r)
91 {
92
93 int e, non_zero;
94
95 unioncxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#
96 {
97 double dcxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#d.;
98 structcxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#$anonymous_type_3# {
99 unsigned char bytecxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#$anonymous_type_3#byte.[8];
100 } ieeecxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#ieee. ;
101 } u;
102
103 u.dcxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#d.= *x ;
104
105 if (little_endian_pcxx . . $ little_endian_p(b126dc7c1de90089).())
106 make_double_bigendiancxx . . $ make_double_bigendian(9757410f5581be28).(&(u.dcxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#d.)) ;
107
108 /* note that r->sign is signed, u.ieee.byte is unsigned */
109
110 if (u.ieeecxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#ieee..bytecxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#$anonymous_type_3#byte.[7]>>7)
111 {
112 r->signcxx . . $ $anonymous_type_5ee4a8f360dc24ad_2#sign. = 1 ;
113 }
114 else
115 {
116 r->signcxx . . $ $anonymous_type_5ee4a8f360dc24ad_2#sign. = 0 ;
117 }
118
119
120 e =(u.ieeecxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#ieee..bytecxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#$anonymous_type_3#byte.[7] & 0x7f)<<4 ^ (u.ieeecxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#ieee..bytecxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#$anonymous_type_3#byte.[6] & 0xf0)>>4 ;
121
122 r->exponentcxx . . $ $anonymous_type_5ee4a8f360dc24ad_2#exponent. = e - 1023 ;
123
124 sprint_nybblecxx . . $ sprint_nybble(577809987ad7a468).(u.ieeecxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#ieee..bytecxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#$anonymous_type_3#byte.[6],r->mantissacxx . . $ $anonymous_type_5ee4a8f360dc24ad_2#mantissa.) ;
125 sprint_bytecxx . . $ sprint_byte(577809987ad7a468).(u.ieeecxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#ieee..bytecxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#$anonymous_type_3#byte.[5],r->mantissacxx . . $ $anonymous_type_5ee4a8f360dc24ad_2#mantissa. + 4) ;
126 sprint_bytecxx . . $ sprint_byte(577809987ad7a468).(u.ieeecxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#ieee..bytecxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#$anonymous_type_3#byte.[4],r->mantissacxx . . $ $anonymous_type_5ee4a8f360dc24ad_2#mantissa. + 12) ;
127 sprint_bytecxx . . $ sprint_byte(577809987ad7a468).(u.ieeecxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#ieee..bytecxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#$anonymous_type_3#byte.[3],r->mantissacxx . . $ $anonymous_type_5ee4a8f360dc24ad_2#mantissa. + 20) ;
128 sprint_bytecxx . . $ sprint_byte(577809987ad7a468).(u.ieeecxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#ieee..bytecxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#$anonymous_type_3#byte.[2],r->mantissacxx . . $ $anonymous_type_5ee4a8f360dc24ad_2#mantissa. + 28) ;
129 sprint_bytecxx . . $ sprint_byte(577809987ad7a468).(u.ieeecxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#ieee..bytecxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#$anonymous_type_3#byte.[1],r->mantissacxx . . $ $anonymous_type_5ee4a8f360dc24ad_2#mantissa. + 36) ;
130 sprint_bytecxx . . $ sprint_byte(577809987ad7a468).(u.ieeecxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#ieee..bytecxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#$anonymous_type_3#byte.[0],r->mantissacxx . . $ $anonymous_type_5ee4a8f360dc24ad_2#mantissa. + 44) ;
131
132 r->mantissacxx . . $ $anonymous_type_5ee4a8f360dc24ad_2#mantissa.[52] = '\0' ;
133
134 non_zero = (u.ieeecxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#ieee..bytecxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#$anonymous_type_3#byte.[0] || u.ieeecxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#ieee..bytecxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#$anonymous_type_3#byte.[1] || u.ieeecxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#ieee..bytecxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#$anonymous_type_3#byte.[2]
135 || u.ieeecxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#ieee..bytecxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#$anonymous_type_3#byte.[3] || u.ieeecxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#ieee..bytecxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#$anonymous_type_3#byte.[4] || u.ieeecxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#ieee..bytecxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#$anonymous_type_3#byte.[5]
136 || (u.ieeecxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#ieee..bytecxx . . $ gsl_ieee_double_to_rep(c86c14603ddda52b).$anonymous_type_2#$anonymous_type_3#byte.[6] & 0x0f)) ;
137
138 r->typecxx . . $ $anonymous_type_5ee4a8f360dc24ad_2#type. = determine_ieee_typecxx . . $ determine_ieee_type(2326284602b0bb2d). (non_zero, e, 2047) ;
139 }
140
141 /* A table of character representations of nybbles */
142
143 static char nybblecxx . . $ nybble.[16][5]={ /* include space for the \0 */
144 "0000", "0001", "0010", "0011",
145 "0100", "0101", "0110", "0111",
146 "1000", "1001", "1010", "1011",
147 "1100", "1101", "1110", "1111"
148 } ;
149
150 static void
151 sprint_nybblecxx . . $ sprint_nybble(577809987ad7a468).(int i, char *s)
152 {
153 char *c ;
154 c=nybblecxx . . $ nybble.[i & 0x0f ];
155 *s=c[0] ; *(s+1)=c[1] ; *(s+2)=c[2] ; *(s+3)=c[3] ;
156 }
157
158 static void
159 sprint_bytecxx . . $ sprint_byte(577809987ad7a468).(int i, char *s)
160 {
161 char *c ;
162 c=nybblecxx . . $ nybble.[(i & 0xf0)>>4];
163 *s=c[0] ; *(s+1)=c[1] ; *(s+2)=c[2] ; *(s+3)=c[3] ;
164 c=nybblecxx . . $ nybble.[i & 0x0f];
165 *(s+4)=c[0] ; *(s+5)=c[1] ; *(s+6)=c[2] ; *(s+7)=c[3] ;
166 }
167
168 static int
169 determine_ieee_typecxx . . $ determine_ieee_type(2326284602b0bb2d). (int non_zero, int exponent, int max_exponent)
170 {
171 if (exponent == max_exponent)
172 {
173 if (non_zero)
174 {
175 return GSL_IEEE_TYPE_NANcxx . . $ GSL_IEEE_TYPE_NAN. ;
176 }
177 else
178 {
179 return GSL_IEEE_TYPE_INFcxx . . $ GSL_IEEE_TYPE_INF. ;
180 }
181 }
182 else if (exponent == 0)
183 {
184 if (non_zero)
185 {
186 return GSL_IEEE_TYPE_DENORMALcxx . . $ GSL_IEEE_TYPE_DENORMAL. ;
187 }
188 else
189 {
190 return GSL_IEEE_TYPE_ZEROcxx . . $ GSL_IEEE_TYPE_ZERO. ;
191 }
192 }
193 else
194 {
195 return GSL_IEEE_TYPE_NORMALcxx . . $ GSL_IEEE_TYPE_NORMAL. ;
196 }
197 }