Skip to content

Commit 9b2e643

Browse files
committed
generation of hexadecimal floating point numbers in tests (squashed)
removed an accidental change, added code to process special cases: NaN and infiinity made required simplications, made corrections in treatment of special cases
1 parent 05875e1 commit 9b2e643

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

src/java_bytecode/expr2java.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ Author: Daniel Kroening, kroening@cs.cmu.edu
88

99

1010
#include <cassert>
11+
#include <sstream>
1112

1213
#include <util/namespace.h>
1314
#include <util/std_types.h>
1415
#include <util/std_expr.h>
1516
#include <util/symbol.h>
1617
#include <util/arith_tools.h>
18+
#include <util/ieee_float.h>
1719

1820
#include <ansi-c/c_qualifiers.h>
1921
#include <ansi-c/c_misc.h>
@@ -235,6 +237,63 @@ 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 float_flag=(src.type()==java_float_type());
247+
if(ieee_repr.is_zero())
248+
{
249+
result+='0';
250+
format_spect fs;
251+
if(fs.precision>0)
252+
{
253+
result+='.';
254+
for(std::size_t i=0; i<fs.precision; i++)
255+
result+='0';
256+
if(float_flag)
257+
result+='f';
258+
}
259+
return(result);
260+
}
261+
262+
if(ieee_repr.is_NaN())
263+
{
264+
if(float_flag)
265+
return("Float.NaN");
266+
else
267+
return("Double.NaN");
268+
}
269+
270+
if(ieee_repr.is_infinity())
271+
{
272+
if(float_flag)
273+
{
274+
if(ieee_repr.get_sign())
275+
return("Float.NEGATIVE_INFINITY");
276+
else
277+
return("Float.POSITIVE_INFINITY");
278+
}
279+
else
280+
{
281+
if(ieee_repr.get_sign())
282+
return("Double.NEGATIVE_INFINITY");
283+
else
284+
return("Double.POSITIVE_INFINITY");
285+
}
286+
}
287+
288+
std::stringstream buffer;
289+
buffer << std::hexfloat;
290+
if(float_flag)
291+
buffer << ieee_repr.to_float() << 'f';
292+
else
293+
buffer << ieee_repr.to_double();
294+
return(buffer.str());
295+
}
296+
238297

239298
return expr2ct::convert_constant(src, precedence);
240299
}

0 commit comments

Comments
 (0)