diff options
| author | Eli Zaretskii | 2017-01-28 10:30:17 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2017-01-28 10:30:17 +0200 |
| commit | c331f393c120208983a4c9890cfd606635ef782a (patch) | |
| tree | dfff4a2ff8ac6d96459560d79eda415f26c67259 | |
| parent | 9f52f67a967819916eedfe55f4ea92f659133dc5 (diff) | |
| download | emacs-c331f393c120208983a4c9890cfd606635ef782a.tar.gz emacs-c331f393c120208983a4c9890cfd606635ef782a.zip | |
Improve documentation of 'format' conversions
* src/editfns.c (Fformat): More accurate description of %g and
effects of the various flags on it. More accurate description of
integer conversions.
* doc/lispref/strings.texi (Formatting Strings): More accurate
description of %g and effects of the various flags on it. More
accurate description of integer conversions. (Bug#25557)
| -rw-r--r-- | doc/lispref/strings.texi | 32 | ||||
| -rw-r--r-- | src/editfns.c | 24 |
2 files changed, 35 insertions, 21 deletions
diff --git a/doc/lispref/strings.texi b/doc/lispref/strings.texi index d343bcf5eff..d5980f62bd4 100644 --- a/doc/lispref/strings.texi +++ b/doc/lispref/strings.texi | |||
| @@ -893,17 +893,18 @@ Functions}). Thus, strings are enclosed in @samp{"} characters, and | |||
| 893 | @item %o | 893 | @item %o |
| 894 | @cindex integer to octal | 894 | @cindex integer to octal |
| 895 | Replace the specification with the base-eight representation of an | 895 | Replace the specification with the base-eight representation of an |
| 896 | integer. | 896 | unsigned integer. |
| 897 | 897 | ||
| 898 | @item %d | 898 | @item %d |
| 899 | Replace the specification with the base-ten representation of an | 899 | Replace the specification with the base-ten representation of a signed |
| 900 | integer. | 900 | integer. |
| 901 | 901 | ||
| 902 | @item %x | 902 | @item %x |
| 903 | @itemx %X | 903 | @itemx %X |
| 904 | @cindex integer to hexadecimal | 904 | @cindex integer to hexadecimal |
| 905 | Replace the specification with the base-sixteen representation of an | 905 | Replace the specification with the base-sixteen representation of an |
| 906 | integer. @samp{%x} uses lower case and @samp{%X} uses upper case. | 906 | unsigned integer. @samp{%x} uses lower case and @samp{%X} uses upper |
| 907 | case. | ||
| 907 | 908 | ||
| 908 | @item %c | 909 | @item %c |
| 909 | Replace the specification with the character which is the value given. | 910 | Replace the specification with the character which is the value given. |
| @@ -918,8 +919,9 @@ floating-point number. | |||
| 918 | 919 | ||
| 919 | @item %g | 920 | @item %g |
| 920 | Replace the specification with notation for a floating-point number, | 921 | Replace the specification with notation for a floating-point number, |
| 921 | using either exponential notation or decimal-point notation, whichever | 922 | using either exponential notation or decimal-point notation. The |
| 922 | is shorter. | 923 | exponential notation is used if the exponent would be less than -4 or |
| 924 | greater than or equal to the precision (default: 6). | ||
| 923 | 925 | ||
| 924 | @item %% | 926 | @item %% |
| 925 | Replace the specification with a single @samp{%}. This format | 927 | Replace the specification with a single @samp{%}. This format |
| @@ -1000,9 +1002,11 @@ both flags are used, @samp{+} takes precedence. | |||
| 1000 | The flag @samp{#} specifies an alternate form which depends on | 1002 | The flag @samp{#} specifies an alternate form which depends on |
| 1001 | the format in use. For @samp{%o}, it ensures that the result begins | 1003 | the format in use. For @samp{%o}, it ensures that the result begins |
| 1002 | with a @samp{0}. For @samp{%x} and @samp{%X}, it prefixes the result | 1004 | with a @samp{0}. For @samp{%x} and @samp{%X}, it prefixes the result |
| 1003 | with @samp{0x} or @samp{0X}. For @samp{%e}, @samp{%f}, and @samp{%g}, | 1005 | with @samp{0x} or @samp{0X}. For @samp{%e} and @samp{%f}, the |
| 1004 | the @samp{#} flag means include a decimal point even if the precision | 1006 | @samp{#} flag means include a decimal point even if the precision is |
| 1005 | is zero. | 1007 | zero. For @samp{%g}, it always includes a decimal point, and also |
| 1008 | forces any trailing zeros after the decimal point to be left in place | ||
| 1009 | where they would otherwise be removed. | ||
| 1006 | 1010 | ||
| 1007 | The flag @samp{0} ensures that the padding consists of @samp{0} | 1011 | The flag @samp{0} ensures that the padding consists of @samp{0} |
| 1008 | characters instead of spaces. This flag is ignored for non-numerical | 1012 | characters instead of spaces. This flag is ignored for non-numerical |
| @@ -1033,10 +1037,14 @@ ignored. | |||
| 1033 | All the specification characters allow an optional @dfn{precision} | 1037 | All the specification characters allow an optional @dfn{precision} |
| 1034 | before the character (after the width, if present). The precision is | 1038 | before the character (after the width, if present). The precision is |
| 1035 | a decimal-point @samp{.} followed by a digit-string. For the | 1039 | a decimal-point @samp{.} followed by a digit-string. For the |
| 1036 | floating-point specifications (@samp{%e}, @samp{%f}, @samp{%g}), the | 1040 | floating-point specifications (@samp{%e} and @samp{%f}), the |
| 1037 | precision specifies how many decimal places to show; if zero, the | 1041 | precision specifies how many digits following the decimal point to |
| 1038 | decimal-point itself is also omitted. For @samp{%s} and @samp{%S}, | 1042 | show; if zero, the decimal-point itself is also omitted. For |
| 1039 | the precision truncates the string to the given width, so @samp{%.3s} | 1043 | @samp{%g}, the precision specifies how many significant digits to show |
| 1044 | (significant digits are the first digit before the decimal point and | ||
| 1045 | all the digits after it). If the precision of %g is zero or | ||
| 1046 | unspecified, it is treated as 1. For @samp{%s} and @samp{%S}, the | ||
| 1047 | precision truncates the string to the given width, so @samp{%.3s} | ||
| 1040 | shows only the first three characters of the representation for | 1048 | shows only the first three characters of the representation for |
| 1041 | @var{object}. For other specification characters, the effect of | 1049 | @var{object}. For other specification characters, the effect of |
| 1042 | precision is what the local library functions of the @code{printf} | 1050 | precision is what the local library functions of the @code{printf} |
diff --git a/src/editfns.c b/src/editfns.c index 395b3f3faed..18384a7d03a 100644 --- a/src/editfns.c +++ b/src/editfns.c | |||
| @@ -3823,12 +3823,14 @@ The format control string may contain %-sequences meaning to substitute | |||
| 3823 | the next available argument: | 3823 | the next available argument: |
| 3824 | 3824 | ||
| 3825 | %s means print a string argument. Actually, prints any object, with `princ'. | 3825 | %s means print a string argument. Actually, prints any object, with `princ'. |
| 3826 | %d means print as number in decimal (%o octal, %x hex). | 3826 | %d means print as signed number in decimal. |
| 3827 | %o means print as unsigned number in octal, %x as unsigned number in hex. | ||
| 3827 | %X is like %x, but uses upper case. | 3828 | %X is like %x, but uses upper case. |
| 3828 | %e means print a number in exponential notation. | 3829 | %e means print a number in exponential notation. |
| 3829 | %f means print a number in decimal-point notation. | 3830 | %f means print a number in decimal-point notation. |
| 3830 | %g means print a number in exponential notation | 3831 | %g means print a number in exponential notation if the exponent would be |
| 3831 | or decimal-point notation, whichever uses fewer characters. | 3832 | less than -4 or greater than or equal to the precision (default: 6); |
| 3833 | otherwise it prints in decimal-point notation. | ||
| 3832 | %c means print a number as a single character. | 3834 | %c means print a number as a single character. |
| 3833 | %S means print any object as an s-expression (using `prin1'). | 3835 | %S means print any object as an s-expression (using `prin1'). |
| 3834 | 3836 | ||
| @@ -3851,8 +3853,10 @@ The - and 0 flags affect the width specifier, as described below. | |||
| 3851 | The # flag means to use an alternate display form for %o, %x, %X, %e, | 3853 | The # flag means to use an alternate display form for %o, %x, %X, %e, |
| 3852 | %f, and %g sequences: for %o, it ensures that the result begins with | 3854 | %f, and %g sequences: for %o, it ensures that the result begins with |
| 3853 | \"0\"; for %x and %X, it prefixes the result with \"0x\" or \"0X\"; | 3855 | \"0\"; for %x and %X, it prefixes the result with \"0x\" or \"0X\"; |
| 3854 | for %e, %f, and %g, it causes a decimal point to be included even if | 3856 | for %e and %f, it causes a decimal point to be included even if the |
| 3855 | the precision is zero. | 3857 | the precision is zero; for %g, it causes a decimal point to be |
| 3858 | included even if the the precision is zero, and also forces trailing | ||
| 3859 | zeros after the decimal point to be left in place. | ||
| 3856 | 3860 | ||
| 3857 | The width specifier supplies a lower limit for the length of the | 3861 | The width specifier supplies a lower limit for the length of the |
| 3858 | printed representation. The padding, if any, normally goes on the | 3862 | printed representation. The padding, if any, normally goes on the |
| @@ -3861,10 +3865,12 @@ character is normally a space, but it is 0 if the 0 flag is present. | |||
| 3861 | The 0 flag is ignored if the - flag is present, or the format sequence | 3865 | The 0 flag is ignored if the - flag is present, or the format sequence |
| 3862 | is something other than %d, %e, %f, and %g. | 3866 | is something other than %d, %e, %f, and %g. |
| 3863 | 3867 | ||
| 3864 | For %e, %f, and %g sequences, the number after the "." in the | 3868 | For %e and %f sequences, the number after the "." in the precision |
| 3865 | precision specifier says how many decimal places to show; if zero, the | 3869 | specifier says how many decimal places to show; if zero, the decimal |
| 3866 | decimal point itself is omitted. For %s and %S, the precision | 3870 | point itself is omitted. For %g, the precision specifies how many |
| 3867 | specifier truncates the string to the given width. | 3871 | significant digits to print; zero or omitted are treated as 1. |
| 3872 | For %s and %S, the precision specifier truncates the string to the | ||
| 3873 | given width. | ||
| 3868 | 3874 | ||
| 3869 | usage: (format STRING &rest OBJECTS) */) | 3875 | usage: (format STRING &rest OBJECTS) */) |
| 3870 | (ptrdiff_t nargs, Lisp_Object *args) | 3876 | (ptrdiff_t nargs, Lisp_Object *args) |