@@ -420,8 +420,6 @@ public static RubyFloat new_float(IRubyObject recv, IRubyObject object) {
420420 return (RubyFloat ) new_float (recv .getRuntime ().getCurrentContext (), object , true );
421421 }
422422
423- private static final ByteList ZEROx = new ByteList (new byte [] { '0' ,'x' }, false );
424-
425423 public static RubyFloat new_float (final Ruby runtime , IRubyObject object ) {
426424 return (RubyFloat ) new_float (runtime .getCurrentContext (), object , true );
427425 }
@@ -540,7 +538,7 @@ public static IRubyObject new_float(ThreadContext context, IRubyObject object, b
540538 throw runtime .newArgumentError ("invalid value for Float(): " + object .inspect ());
541539 }
542540
543- if (bytes . startsWith ( ZEROx )) { // startsWith("0x")
541+ if (isHexValue ( bytes )) {
544542 if (bytes .indexOf ('p' ) != -1 || bytes .indexOf ('P' ) != -1 ) {
545543 return runtime .newFloat (parseHexidecimalExponentString2 (runtime , bytes ));
546544 }
@@ -567,6 +565,12 @@ public static IRubyObject new_float(ThreadContext context, IRubyObject object, b
567565 return TypeConverter .handleUncoercibleObject (runtime , object , runtime .getFloat (), true );
568566 }
569567
568+ static boolean isHexValue (ByteList bytes ) {
569+ int length = bytes .getRealSize ();
570+ int index = length >= 1 && bytes .get (0 ) == '-' ? 1 : 0 ;
571+ return length >= index + 2 && bytes .get (index ) == '0' && (bytes .get (index + 1 ) == 'x' || bytes .get (index + 1 ) == 'X' );
572+ }
573+
570574 static RubyFloat new_float (final Ruby runtime , RubyInteger num ) {
571575 if (num instanceof RubyBignum ) {
572576 return RubyFloat .newFloat (runtime , RubyBignum .big2dbl ((RubyBignum ) num ));
0 commit comments