|
9 | 9 | #include "expr2java.h"
|
10 | 10 |
|
11 | 11 | #include <cassert>
|
| 12 | +#include <sstream> |
12 | 13 |
|
13 | 14 | #include <util/namespace.h>
|
14 | 15 | #include <util/std_types.h>
|
15 | 16 | #include <util/std_expr.h>
|
16 | 17 | #include <util/symbol.h>
|
17 | 18 | #include <util/arith_tools.h>
|
| 19 | +#include <util/ieee_float.h> |
18 | 20 |
|
19 | 21 | #include <ansi-c/c_qualifiers.h>
|
20 | 22 | #include <ansi-c/c_misc.h>
|
@@ -235,6 +237,58 @@ std::string expr2javat::convert_constant(
|
235 | 237 | dest+='L';
|
236 | 238 | return dest;
|
237 | 239 | }
|
| 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 | + |
238 | 292 |
|
239 | 293 | return expr2ct::convert_constant(src, precedence);
|
240 | 294 | }
|
|
0 commit comments