Skip to content

Commit 3eab185

Browse files
eigoldMatthias Güdemann
authored and
Matthias Güdemann
committed
generation of hexadecimal floating point numbers in tests
outputs NaN, positive/negative infinity and positive/negative zero
1 parent ce7c498 commit 3eab185

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

src/java_bytecode/expr2java.cpp

+54
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ Author: Daniel Kroening, [email protected]
99
#include "expr2java.h"
1010

1111
#include <cassert>
12+
#include <sstream>
1213

1314
#include <util/namespace.h>
1415
#include <util/std_types.h>
1516
#include <util/std_expr.h>
1617
#include <util/symbol.h>
1718
#include <util/arith_tools.h>
19+
#include <util/ieee_float.h>
1820

1921
#include <ansi-c/c_qualifiers.h>
2022
#include <ansi-c/c_misc.h>
@@ -235,6 +237,58 @@ std::string expr2javat::convert_constant(
235237
dest+='L';
236238
return dest;
237239
}
240+
else if((src.type()==java_float_type()) ||
241+
(src.type()==java_double_type()))
242+
{
243+
ieee_floatt ieee_repr(to_constant_expr(src));
244+
std::string result;
245+
246+
bool is_java_float=(src.type()==java_float_type());
247+
if(ieee_repr.is_zero())
248+
{
249+
if(ieee_repr.get_sign())
250+
result+='-';
251+
result+="0.0";
252+
if(is_java_float)
253+
result+='f';
254+
return result;
255+
}
256+
257+
if(ieee_repr.is_NaN())
258+
{
259+
if(is_java_float)
260+
return "Float.NaN";
261+
else
262+
return "Double.NaN";
263+
}
264+
265+
if(ieee_repr.is_infinity())
266+
{
267+
if(is_java_float)
268+
{
269+
if(ieee_repr.get_sign())
270+
return "Float.NEGATIVE_INFINITY";
271+
else
272+
return "Float.POSITIVE_INFINITY";
273+
}
274+
else
275+
{
276+
if(ieee_repr.get_sign())
277+
return "Double.NEGATIVE_INFINITY";
278+
else
279+
return "Double.POSITIVE_INFINITY";
280+
}
281+
}
282+
283+
std::stringstream buffer;
284+
buffer << std::hexfloat;
285+
if(is_java_float)
286+
buffer << ieee_repr.to_float() << 'f';
287+
else
288+
buffer << ieee_repr.to_double();
289+
return buffer.str();
290+
}
291+
238292

239293
return expr2ct::convert_constant(src, precedence);
240294
}

0 commit comments

Comments
 (0)