Skip to content

added check for float and double using if-statements #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions lib/WALASupport/InstrKindInfoGetter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,22 +233,29 @@ jobject InstrKindInfoGetter::handleFloatLiteralInst() {
FloatLiteralInst* castInst = cast<FloatLiteralInst>(instr);
APFloat value = castInst->getValue();

if (value.isFinite()) {
if (&value.getSemantics() == &APFloat::IEEEsingle()) {
// To Float
node = (*wala)->makeConstant(value.convertToFloat());
}
else if (&value.getSemantics() == &APFloat::IEEEdouble()) {
// To Double
node = (*wala)->makeConstant(value.convertToDouble());
}
else if (value.isFinite()) {
// To BigDecimal
SmallVector<char, 128> buf;
value.toString(buf);
jobject bigDecimal = (*wala).makeBigDecimal(buf.data(), buf.size());
node = (*wala)->makeConstant(bigDecimal);
nodeMap->insert(std::make_pair(castInst, node));
}
else {
// Infinity or NaN, convert to double
// as BigDecimal constructor cannot accept strings of these
bool APFLosesInfo;
value.convert(APFloat::IEEEdouble(), APFloat::rmNearestTiesToEven, &APFLosesInfo);
node = (*wala)->makeConstant(value.convertToDouble());
nodeMap->insert(std::make_pair(castInst, node));
}
nodeMap->insert(std::make_pair(castInst, node));
return node;
}

Expand Down