diff options
| author | Jim Blandy | 1993-07-18 06:26:28 +0000 |
|---|---|---|
| committer | Jim Blandy | 1993-07-18 06:26:28 +0000 |
| commit | c7b1427704903fe949a674ebcbade65161f5e43b (patch) | |
| tree | 0bb3f996e5463169f97264f25b334f0170bdd68b /src | |
| parent | e87206440141f2cad44d913dd558edc7f60a17cb (diff) | |
| download | emacs-c7b1427704903fe949a674ebcbade65161f5e43b.tar.gz emacs-c7b1427704903fe949a674ebcbade65161f5e43b.zip | |
* print.c (float_to_string): Distinguish between a precision of
zero and an omitted precision. Do allow %.0f to produce strings
containing no decimal point or exponent.
(syms_of_print): Doc fix for float-output-format.
Diffstat (limited to 'src')
| -rw-r--r-- | src/print.c | 59 |
1 files changed, 33 insertions, 26 deletions
diff --git a/src/print.c b/src/print.c index cd295fcdc0e..0d909432cf6 100644 --- a/src/print.c +++ b/src/print.c | |||
| @@ -610,8 +610,8 @@ float_to_string (buf, data) | |||
| 610 | unsigned char *buf; | 610 | unsigned char *buf; |
| 611 | double data; | 611 | double data; |
| 612 | { | 612 | { |
| 613 | register unsigned char *cp, c; | 613 | unsigned char *cp; |
| 614 | register int width; | 614 | int width = -1; |
| 615 | 615 | ||
| 616 | if (NILP (Vfloat_output_format) | 616 | if (NILP (Vfloat_output_format) |
| 617 | || XTYPE (Vfloat_output_format) != Lisp_String) | 617 | || XTYPE (Vfloat_output_format) != Lisp_String) |
| @@ -630,18 +630,20 @@ float_to_string (buf, data) | |||
| 630 | goto lose; | 630 | goto lose; |
| 631 | 631 | ||
| 632 | cp += 2; | 632 | cp += 2; |
| 633 | for (width = 0; | 633 | |
| 634 | ((c = *cp) >= '0' && c <= '9'); | 634 | /* Check the width specification. */ |
| 635 | cp++) | 635 | if ('0' <= *cp && *cp <= '9') |
| 636 | { | 636 | for (width = 0; (*cp >= '0' && *cp <= '9'); cp++) |
| 637 | width *= 10; | 637 | width = (width * 10) + (*cp - '0'); |
| 638 | width += c - '0'; | ||
| 639 | } | ||
| 640 | 638 | ||
| 641 | if (*cp != 'e' && *cp != 'f' && *cp != 'g') | 639 | if (*cp != 'e' && *cp != 'f' && *cp != 'g') |
| 642 | goto lose; | 640 | goto lose; |
| 643 | 641 | ||
| 644 | if (width < (*cp != 'e') || width > DBL_DIG) | 642 | /* A precision of zero is valid for %f; everything else requires |
| 643 | at least one. Width may be omitted anywhere. */ | ||
| 644 | if (width != -1 | ||
| 645 | && (width < (*cp != 'f') | ||
| 646 | || width > DBL_DIG)) | ||
| 645 | goto lose; | 647 | goto lose; |
| 646 | 648 | ||
| 647 | if (cp[1] != 0) | 649 | if (cp[1] != 0) |
| @@ -650,23 +652,28 @@ float_to_string (buf, data) | |||
| 650 | sprintf (buf, XSTRING (Vfloat_output_format)->data, data); | 652 | sprintf (buf, XSTRING (Vfloat_output_format)->data, data); |
| 651 | } | 653 | } |
| 652 | 654 | ||
| 653 | /* Make sure there is a decimal point with digit after, or an exponent, | 655 | /* Make sure there is a decimal point with digit after, or an |
| 654 | so that the value is readable as a float. */ | 656 | exponent, so that the value is readable as a float. But don't do |
| 655 | for (cp = buf; *cp; cp++) | 657 | this with "%.0f"; it's legal for that not to produce a decimal |
| 656 | if ((*cp < '0' || *cp > '9') && *cp != '-') | 658 | point. */ |
| 657 | break; | 659 | if (*cp != 'f' || width != 0) |
| 658 | |||
| 659 | if (*cp == '.' && cp[1] == 0) | ||
| 660 | { | 660 | { |
| 661 | cp[1] = '0'; | 661 | for (cp = buf; *cp; cp++) |
| 662 | cp[2] = 0; | 662 | if ((*cp < '0' || *cp > '9') && *cp != '-') |
| 663 | } | 663 | break; |
| 664 | 664 | ||
| 665 | if (*cp == 0) | 665 | if (*cp == '.' && cp[1] == 0) |
| 666 | { | 666 | { |
| 667 | *cp++ = '.'; | 667 | cp[1] = '0'; |
| 668 | *cp++ = '0'; | 668 | cp[2] = 0; |
| 669 | *cp++ = 0; | 669 | } |
| 670 | |||
| 671 | if (*cp == 0) | ||
| 672 | { | ||
| 673 | *cp++ = '.'; | ||
| 674 | *cp++ = '0'; | ||
| 675 | *cp++ = 0; | ||
| 676 | } | ||
| 670 | } | 677 | } |
| 671 | } | 678 | } |
| 672 | #endif /* LISP_FLOAT_TYPE */ | 679 | #endif /* LISP_FLOAT_TYPE */ |
| @@ -1030,7 +1037,7 @@ Use `f' for decimal point notation \"DIGITS.DIGITS\".\n\ | |||
| 1030 | Use `g' to choose the shorter of those two formats for the number at hand.\n\ | 1037 | Use `g' to choose the shorter of those two formats for the number at hand.\n\ |
| 1031 | The precision in any of these cases is the number of digits following\n\ | 1038 | The precision in any of these cases is the number of digits following\n\ |
| 1032 | the decimal point. With `f', a precision of 0 means to omit the\n\ | 1039 | the decimal point. With `f', a precision of 0 means to omit the\n\ |
| 1033 | decimal point. 0 is not allowed with `f' or `g'.\n\n\ | 1040 | decimal point. 0 is not allowed with `e' or `g'.\n\n\ |
| 1034 | A value of nil means to use `%.20g'."); | 1041 | A value of nil means to use `%.20g'."); |
| 1035 | Vfloat_output_format = Qnil; | 1042 | Vfloat_output_format = Qnil; |
| 1036 | Qfloat_output_format = intern ("float-output-format"); | 1043 | Qfloat_output_format = intern ("float-output-format"); |