public static String numberToString(double d, int base) { if (d != d) return "NaN"; if (d == Double.POSITIVE_INFINITY) return "Infinity"; if (d == Double.NEGATIVE_INFINITY) return "-Infinity"; if (d == 0.0) return "0"; if ((base < 2) || (base > 36)) { throw Context.reportRuntimeError1( "msg.bad.radix", Integer.toString(base)); } if (base != 10) { return DToA.JS_dtobasestr(base, d); } else { // V8 FastDtoa can't convert all numbers, so try it first but // fall back to old DToA in case it fails String result = FastDtoa.numberToString(d); if (result != null) { return result; } StringBuilder buffer = new StringBuilder(); DToA.JS_dtostr(buffer, DToA.DTOSTR_STANDARD, 0, d); return buffer.toString(); } }
public static String numberToString(double d, int base) { if ((base < 2) || (base > 36)) { throw Context.reportRuntimeError1( "msg.bad.radix", Integer.toString(base)); } if (d != d) return "NaN"; if (d == Double.POSITIVE_INFINITY) return "Infinity"; if (d == Double.NEGATIVE_INFINITY) return "-Infinity"; if (d == 0.0) return "0"; if (base != 10) { return DToA.JS_dtobasestr(base, d); } else { // V8 FastDtoa can't convert all numbers, so try it first but // fall back to old DToA in case it fails String result = FastDtoa.numberToString(d); if (result != null) { return result; } StringBuilder buffer = new StringBuilder(); DToA.JS_dtostr(buffer, DToA.DTOSTR_STANDARD, 0, d); return buffer.toString(); } }
public static String numberToString(double d, int base) { if (Double.isNaN(d)) return "NaN"; if (d == Double.POSITIVE_INFINITY) return "Infinity"; if (d == Double.NEGATIVE_INFINITY) return "-Infinity"; if (d == 0.0) return "0"; if ((base < 2) || (base > 36)) { throw Context.reportRuntimeError1( "msg.bad.radix", Integer.toString(base)); } if (base != 10) { return DToA.JS_dtobasestr(base, d); } else { // V8 FastDtoa can't convert all numbers, so try it first but // fall back to old DToA in case it fails String result = FastDtoa.numberToString(d); if (result != null) { return result; } StringBuilder buffer = new StringBuilder(); DToA.JS_dtostr(buffer, DToA.DTOSTR_STANDARD, 0, d); return buffer.toString(); } }
private static String ToStringSlow(double value) { // call DToA for general number-to-string String result = FastDtoa.numberToString(value); if (result != null) { return result; } StringBuilder buffer = new StringBuilder(); DToA.JS_dtostr(buffer, DToA.DTOSTR_STANDARD, 0, value); return buffer.toString(); }