forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit6eb3eb5
committed
Improve snprintf.c's handling of NaN, Infinity, and minus zero.
Up to now, float4out/float8out handled NaN and Infinity cases explicitly,and invoked psprintf only for ordinary float values. This was done becauseplatform implementations of snprintf produce varying representations ofthese special cases. But now that we use snprintf.c always, it's betterto give it the responsibility to produce a uniform representation ofthese cases, so that we have uniformity across the board not only infloat4out/float8out. Hence, move that work into fmtfloat().Also, teach fmtfloat() to recognize IEEE minus zero and handle itcorrectly. The previous coding worked only accidentally, and wouldfail for e.g. "%+f" format (it'd print "+-0.00000"). Now that we'reusing snprintf.c everywhere, it's not acceptable for it to do weirdthings in corner cases. (This incidentally avoids a portabilityproblem we've seen on some really ancient platforms, that nativesprintf does the wrong thing with minus zero.)Also, introduce a new entry point in snprintf.c to allow float[48]outto bypass the work of interpreting a well-known format spec, as wellas bypassing the overhead of the psprintf layer. I modeled this APIloosely on strfromd(). In my testing, this brings float[48]out backto approximately the same speed they had when using native snprintf,fixing one of the main performance issues caused by using snprintf.c.(There is some talk of more aggressive work to improve the speed offloating-point output conversion, but these changes seem to providea better starting point for such work anyway.)Getting rid of the previous ad-hoc hack for Infinity/NaN in fmtfloat()allows removing <ctype.h> from snprintf.c's #includes. I also removeda few other #includes that I think are historical, though the buildfarmmay expose that as wrong.Discussion:https://postgr.es/m/13178.1538794717@sss.pgh.pa.us1 parentf9eb7c1 commit6eb3eb5
3 files changed
+145
-74
lines changedLines changed: 6 additions & 46 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
243 | 243 |
| |
244 | 244 |
| |
245 | 245 |
| |
246 |
| - | |
247 |
| - | |
248 |
| - | |
249 |
| - | |
250 |
| - | |
251 |
| - | |
252 |
| - | |
253 |
| - | |
254 |
| - | |
255 |
| - | |
256 |
| - | |
257 |
| - | |
258 |
| - | |
259 |
| - | |
260 |
| - | |
261 |
| - | |
262 |
| - | |
263 |
| - | |
264 |
| - | |
265 |
| - | |
266 |
| - | |
267 |
| - | |
268 |
| - | |
| 246 | + | |
| 247 | + | |
269 | 248 |
| |
| 249 | + | |
270 | 250 |
| |
271 | 251 |
| |
272 | 252 |
| |
| |||
479 | 459 |
| |
480 | 460 |
| |
481 | 461 |
| |
482 |
| - | |
483 |
| - | |
484 |
| - | |
485 |
| - | |
486 |
| - | |
487 |
| - | |
488 |
| - | |
489 |
| - | |
490 |
| - | |
491 |
| - | |
492 |
| - | |
493 |
| - | |
494 |
| - | |
495 |
| - | |
496 |
| - | |
497 |
| - | |
498 |
| - | |
499 |
| - | |
500 |
| - | |
501 |
| - | |
502 |
| - | |
503 |
| - | |
504 |
| - | |
| 462 | + | |
| 463 | + | |
505 | 464 |
| |
| 465 | + | |
506 | 466 |
| |
507 | 467 |
| |
508 | 468 |
| |
|
Lines changed: 3 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
187 | 187 |
| |
188 | 188 |
| |
189 | 189 |
| |
| 190 | + | |
| 191 | + | |
| 192 | + | |
190 | 193 |
| |
191 | 194 |
| |
192 | 195 |
| |
|
Lines changed: 136 additions & 28 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
33 | 33 |
| |
34 | 34 |
| |
35 | 35 |
| |
36 |
| - | |
37 |
| - | |
38 | 36 |
| |
39 |
| - | |
40 |
| - | |
41 |
| - | |
42 |
| - | |
43 | 37 |
| |
44 | 38 |
| |
45 | 39 |
| |
| |||
1111 | 1105 |
| |
1112 | 1106 |
| |
1113 | 1107 |
| |
1114 |
| - | |
1115 |
| - | |
1116 |
| - | |
1117 |
| - | |
1118 | 1108 |
| |
1119 | 1109 |
| |
1120 | 1110 |
| |
| |||
1128 | 1118 |
| |
1129 | 1119 |
| |
1130 | 1120 |
| |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
1131 | 1124 |
| |
1132 | 1125 |
| |
1133 | 1126 |
| |
1134 | 1127 |
| |
1135 | 1128 |
| |
1136 |
| - | |
| 1129 | + | |
1137 | 1130 |
| |
1138 |
| - | |
1139 |
| - | |
1140 |
| - | |
1141 |
| - | |
1142 |
| - | |
1143 |
| - | |
1144 |
| - | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
1145 | 1134 |
| |
1146 | 1135 |
| |
1147 | 1136 |
| |
1148 |
| - | |
1149 |
| - | |
1150 |
| - | |
1151 |
| - | |
1152 |
| - | |
1153 |
| - | |
1154 |
| - | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
1155 | 1150 |
| |
1156 |
| - | |
1157 |
| - | |
1158 |
| - | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
1159 | 1177 |
| |
1160 | 1178 |
| |
1161 | 1179 |
| |
| |||
1197 | 1215 |
| |
1198 | 1216 |
| |
1199 | 1217 |
| |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
1200 | 1308 |
| |
1201 | 1309 |
| |
1202 | 1310 |
| |
|
0 commit comments
Comments
(0)