113 doTest(fmt, randomDouble(1e-50)); 114 doTest(fmt, randomDouble(1e100)); 115 // The use of double d such that isInfinite(100d) causes the 116 // numeric test to fail with percent formats (bug 4266589). 117 // Largest double s.t. 100d < Inf: d=1.7976931348623156E306 118 doTest(fmt, randomDouble(1e306)); 119 doTest(fmt, randomDouble(1e-323)); 120 doTest(fmt, randomDouble(1e-100)); 121 } 122 } 123 124 /** 125 * Return a random value from -range..+range. 126 */ 127 public double randomDouble(double range) { 128 double a = Math.random(); 129 return (2.0 * range * a) - range; 130 } 131 132 public void doTest(NumberFormat fmt, double value) { 133 doTest(fmt, new Double(value)); 134 } 135 136 public void doTest(NumberFormat fmt, long value) { 137 doTest(fmt, new Long(value)); 138 } 139 140 static double proportionalError(Number a, Number b) { 141 double aa = a.doubleValue(), bb = b.doubleValue(); 142 double error = aa - bb; 143 if (aa != 0 && bb != 0) error /= aa; 144 return Math.abs(error); 145 } 146 147 public void doTest(NumberFormat fmt, Number value) { 148 fmt.setMaximumFractionDigits(Integer.MAX_VALUE); 149 String s = fmt.format(value), s2 = null; 150 Number n = null; 151 String err = ""; 152 try { 153 if (DEBUG) logln(" " + value + " F> " + escape(s)); 154 n = fmt.parse(s); 155 if (DEBUG) logln(" " + escape(s) + " P> " + n); 156 s2 = fmt.format(n); 157 if (DEBUG) logln(" " + n + " F> " + escape(s2)); | 113 doTest(fmt, randomDouble(1e-50)); 114 doTest(fmt, randomDouble(1e100)); 115 // The use of double d such that isInfinite(100d) causes the 116 // numeric test to fail with percent formats (bug 4266589). 117 // Largest double s.t. 100d < Inf: d=1.7976931348623156E306 118 doTest(fmt, randomDouble(1e306)); 119 doTest(fmt, randomDouble(1e-323)); 120 doTest(fmt, randomDouble(1e-100)); 121 } 122 } 123 124 /** 125 * Return a random value from -range..+range. 126 */ 127 public double randomDouble(double range) { 128 double a = Math.random(); 129 return (2.0 * range * a) - range; 130 } 131 132 public void doTest(NumberFormat fmt, double value) { 133 doTest(fmt, Double.valueOf(value)); 134 } 135 136 public void doTest(NumberFormat fmt, long value) { 137 doTest(fmt, Long.valueOf(value)); 138 } 139 140 static double proportionalError(Number a, Number b) { 141 double aa = a.doubleValue(), bb = b.doubleValue(); 142 double error = aa - bb; 143 if (aa != 0 && bb != 0) error /= aa; 144 return Math.abs(error); 145 } 146 147 public void doTest(NumberFormat fmt, Number value) { 148 fmt.setMaximumFractionDigits(Integer.MAX_VALUE); 149 String s = fmt.format(value), s2 = null; 150 Number n = null; 151 String err = ""; 152 try { 153 if (DEBUG) logln(" " + value + " F> " + escape(s)); 154 n = fmt.parse(s); 155 if (DEBUG) logln(" " + escape(s) + " P> " + n); 156 s2 = fmt.format(n); 157 if (DEBUG) logln(" " + n + " F> " + escape(s2)); |