comparison Objects/floatobject.c @ 53442:6947bc3dd433 legacy-trunk

Issue #5835, deprecate PyOS_ascii_formatd. If anyone wants to clean up the documentation, feel free. It's my first documentation foray, and it's not that great. Will port to py3k with a different strategy.
author Eric Smith <eric@trueblade.com>
date Sat, 25 Apr 2009 21:40:15 +0000
parents 6bcdc131f53c
children 01c3363a357f
comparison
equal deleted inserted replaced
53441:81aeb8bc659d 53442:6947bc3dd433
340 340
341 static void 341 static void
342 format_float(char *buf, size_t buflen, PyFloatObject *v, int precision) 342 format_float(char *buf, size_t buflen, PyFloatObject *v, int precision)
343 { 343 {
344 register char *cp; 344 register char *cp;
345 char format[32];
346 int i; 345 int i;
347 346
348 /* Subroutine for float_repr and float_print. 347 /* Subroutine for float_repr and float_print.
349 We want float numbers to be recognizable as such, 348 We want float numbers to be recognizable as such,
350 i.e., they should contain a decimal point or an exponent. 349 i.e., they should contain a decimal point or an exponent.
351 However, %g may print the number as an integer; 350 However, %g may print the number as an integer;
352 in such cases, we append ".0" to the string. */ 351 in such cases, we append ".0" to the string. */
353 352
354 assert(PyFloat_Check(v)); 353 assert(PyFloat_Check(v));
355 PyOS_snprintf(format, 32, "%%.%ig", precision); 354 _PyOS_double_to_string(buf, buflen, v->ob_fval, 'g', precision,
356 PyOS_ascii_formatd(buf, buflen, format, v->ob_fval); 355 0, NULL);
357 cp = buf; 356 cp = buf;
358 if (*cp == '-') 357 if (*cp == '-')
359 cp++; 358 cp++;
360 for (; *cp != '\0'; cp++) { 359 for (; *cp != '\0'; cp++) {
361 /* Any non-digit means it's not an integer; 360 /* Any non-digit means it's not an integer;