Skip to content

Commit

Permalink
[Truffle] Try fallback string to float parsing when parseDouble fails
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Fish committed Dec 17, 2016
1 parent a14acdb commit 415acd5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
5 changes: 0 additions & 5 deletions spec/truffle/tags/core/string/modulo_tags.txt

This file was deleted.

Expand Up @@ -3460,7 +3460,8 @@ public static abstract class StringToFPrimitiveNode extends PrimitiveArrayArgume

@TruffleBoundary(throwsControlFlowException = true)
@Specialization
public Object stringToF(DynamicObject string, boolean strict) {
public Object stringToF(DynamicObject string, boolean strict,
@Cached("create(getContext(), getSourceSection())") FixnumOrBignumNode fixnumOrBignumNode) {
final Rope rope = rope(string);
final ByteList byteList = RopeOperations.getByteListReadOnly(rope);
if (byteList.getRealSize() == 0) {
Expand All @@ -3470,7 +3471,17 @@ public Object stringToF(DynamicObject string, boolean strict) {
try {
return Double.parseDouble(string.toString());
} catch (NumberFormatException e) {
return null;
// Try falling back to this implementation if the first fails, niether 100% complete
final Object result = ConvertBytes.byteListToInum19(getContext(), this, fixnumOrBignumNode, string, 16, true);
if (result instanceof Integer) {
return ((Integer) result).doubleValue();
} else if (result instanceof Long) {
return ((Long) result).doubleValue();
} else if (result instanceof Double) {
return result;
} else {
return null;
}
}
}
try {
Expand Down

0 comments on commit 415acd5

Please sign in to comment.