@@ -152,16 +152,19 @@ private static int stringSize(long x) {
152152 }
153153
154154 private static final int POW10 [] = {1 , 10 , 100 , 1000 , 10000 , 100000 , 1000000 };
155- private static final long MAX_DOUBLE_TO_WRITE = Long .MAX_VALUE / 1000000 - 1 ;
156155
157156 public static final void writeFloat (JsonStream stream , float val ) throws IOException {
158157 if (val < 0 ) {
159158 stream .write ('-' );
160159 val = -val ;
161160 }
161+ if (val > 0x4ffffff ) {
162+ stream .writeRaw (Float .toString (val ));
163+ return ;
164+ }
162165 int precision = 6 ;
163- int exp = POW10 [ precision ];
164- long lval = (long )(val * exp + 0.5 );
166+ int exp = 1000000 ; // 6
167+ long lval = (long )(( double ) val * exp + 0.5 );
165168 stream .writeVal (lval / exp );
166169 long fval = lval % exp ;
167170 if (fval == 0 ) {
@@ -172,7 +175,7 @@ public static final void writeFloat(JsonStream stream, float val) throws IOExcep
172175 stream .flushBuffer ();
173176 }
174177 for (int p = precision - 1 ; p > 0 && fval < POW10 [p ]; p --) {
175- stream .write ( '0' ) ;
178+ stream .buf [ stream . count ++] = '0' ;
176179 }
177180 stream .writeVal (fval );
178181 while (stream .buf [stream .count -1 ] == '0' ) {
@@ -185,12 +188,12 @@ public static final void writeDouble(JsonStream stream, double val) throws IOExc
185188 val = -val ;
186189 stream .write ('-' );
187190 }
188- if (val > MAX_DOUBLE_TO_WRITE ) {
191+ if (val > 0x4ffffff ) {
189192 stream .writeRaw (Double .toString (val ));
190193 return ;
191194 }
192195 int precision = 6 ;
193- int exp = POW10 [ precision ];
196+ int exp = 1000000 ; // 6
194197 long lval = (long )(val * exp + 0.5 );
195198 stream .writeVal (lval / exp );
196199 long fval = lval % exp ;
@@ -202,7 +205,7 @@ public static final void writeDouble(JsonStream stream, double val) throws IOExc
202205 stream .flushBuffer ();
203206 }
204207 for (int p = precision - 1 ; p > 0 && fval < POW10 [p ]; p --) {
205- stream .write ( '0' ) ;
208+ stream .buf [ stream . count ++] = '0' ;
206209 }
207210 stream .writeVal (fval );
208211 while (stream .buf [stream .count -1 ] == '0' ) {
0 commit comments