Skip to content

Commit

Permalink
Showing 3 changed files with 18 additions and 16 deletions.
12 changes: 0 additions & 12 deletions spec/truffle/tags/core/kernel/Float_tags.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
fails:Kernel.Float raises an ArgumentError for a String of numbers followed by word characters
fails:Kernel.Float returns a value for a String with an embedded _
fails:Kernel.Float raises an ArgumentError for a String with an embedded \0
fails:Kernel.Float raises an ArgumentError for a String with a trailing \0
fails:Kernel.Float allows embedded _ in a number on either side of the e
fails:Kernel.Float allows embedded _ in a number on either side of the E
fails:Kernel#Float raises an ArgumentError for a String of numbers followed by word characters
fails:Kernel#Float returns a value for a String with an embedded _
fails:Kernel#Float raises an ArgumentError for a String with an embedded \0
fails:Kernel#Float raises an ArgumentError for a String with a trailing \0
fails:Kernel#Float allows embedded _ in a number on either side of the e
fails:Kernel#Float allows embedded _ in a number on either side of the E
fails:Kernel.Float for hexadecimal literals with binary exponent allows embedded _ in a number on either side of the p
fails:Kernel.Float for hexadecimal literals with binary exponent allows embedded _ in a number on either side of the P
fails:Kernel#Float for hexadecimal literals with binary exponent allows embedded _ in a number on either side of the p
Original file line number Diff line number Diff line change
@@ -3260,13 +3260,27 @@ public static abstract class StringToFPrimitiveNode extends PrimitiveArrayArgume
@TruffleBoundary
@Specialization
public Object stringToF(DynamicObject string, boolean strict) {
final Rope rope = rope(string);
final ByteList byteList = RopeOperations.getByteListReadOnly(rope);
if (byteList.getRealSize() == 0) {
throw new RaiseException(coreExceptions().argumentError("invalid value for Float()", this));
}
if (string.toString().startsWith("0x")) {
try {
return Double.parseDouble(string.toString());
} catch (NumberFormatException e) {
return null;
}
}
try {
return Double.parseDouble(string.toString());
return ConvertDouble.byteListToDouble19(byteList, strict);
} catch (NumberFormatException e) {
return null;
if (strict) {
throw new RaiseException(coreExceptions().argumentError("invalid value for Float()", this));
}
return 0.0;
}
}

}

@Primitive(name = "string_index", lowerFixnum = 2)
2 changes: 1 addition & 1 deletion truffle/src/main/ruby/core/type.rb
Original file line number Diff line number Diff line change
@@ -114,7 +114,7 @@ def self.module_inspect(mod)
end

def self.coerce_string_to_float(string, strict)
value = Truffle.invoke_primitive :string_to_f, string, strict
value = Truffle.invoke_primitive :string_to_f, StringValue(string), strict
raise ArgumentError, "invalid string for Float" if value.nil?
value
end

0 comments on commit 5cceef7

Please sign in to comment.