@@ -1147,6 +1147,9 @@ int js_dtoa(char *buf, double d, int radix, int n_digits, int flags,
1147
1147
P = n_digits + 1 ;
1148
1148
else
1149
1149
P = n_digits ;
1150
+ /* "-0" is displayed as "0" if JS_DTOA_MINUS_ZERO is not present */
1151
+ if (sgn && (flags & JS_DTOA_MINUS_ZERO ))
1152
+ * q ++ = '-' ;
1150
1153
goto output ;
1151
1154
}
1152
1155
/* denormal number: convert to a normal number */
@@ -1156,6 +1159,8 @@ int js_dtoa(char *buf, double d, int radix, int n_digits, int flags,
1156
1159
} else {
1157
1160
m |= (uint64_t )1 << 52 ;
1158
1161
}
1162
+ if (sgn )
1163
+ * q ++ = '-' ;
1159
1164
/* remove the bias */
1160
1165
e -= 1022 ;
1161
1166
/* d = 2^(e-53)*m */
@@ -1167,8 +1172,6 @@ int js_dtoa(char *buf, double d, int radix, int n_digits, int flags,
1167
1172
(flags & JS_DTOA_EXP_MASK ) != JS_DTOA_EXP_ENABLED ) {
1168
1173
m >>= 53 - e ;
1169
1174
/* 'm' is never zero */
1170
- if (sgn )
1171
- * q ++ = '-' ;
1172
1175
q += u64toa_radix (q , m , radix );
1173
1176
goto done ;
1174
1177
}
@@ -1244,10 +1247,6 @@ int js_dtoa(char *buf, double d, int radix, int n_digits, int flags,
1244
1247
/* frac is rounded using RNDNA */
1245
1248
mul_pow_round (tmp1 , m , e - 53 , radix1 , radix_shift , n_digits , JS_RNDNA );
1246
1249
1247
- /* "-0" is displayed as "0" */
1248
- if (sgn && !(tmp1 -> tab [0 ] == 0 && tmp1 -> len == 1 )) {
1249
- * q ++ = '-' ;
1250
- }
1251
1250
/* we add one extra digit on the left and remove it if needed
1252
1251
to avoid testing if the result is < radix^P */
1253
1252
len = output_digits (q , tmp1 , radix , max_int (E + 1 , 1 ) + n_digits ,
@@ -1277,11 +1276,6 @@ int js_dtoa(char *buf, double d, int radix, int n_digits, int flags,
1277
1276
}
1278
1277
}
1279
1278
output :
1280
- /* "-0" is displayed as "0" if JS_DTOA_MINUS_ZERO is not present */
1281
- if (sgn && ((flags & JS_DTOA_MINUS_ZERO ) ||
1282
- !(tmp1 -> tab [0 ] == 0 && tmp1 -> len == 1 ))) {
1283
- * q ++ = '-' ;
1284
- }
1285
1279
if (fmt == JS_DTOA_FORMAT_FIXED )
1286
1280
E_max = n_digits ;
1287
1281
else
0 commit comments