* bug#25557: Documentation of format doesn't describe "g" accurately
@ 2017-01-27 22:05 Clément Pit--Claudel
2017-01-28 8:37 ` Eli Zaretskii
0 siblings, 1 reply; 13+ messages in thread
From: Clément Pit--Claudel @ 2017-01-27 22:05 UTC (permalink / raw)
To: 25557
[-- Attachment #1.1: Type: text/plain, Size: 1133 bytes --]
Hi emacs,
There seems to be a few issues in the docstring of `format':
> %g means print a number in exponential notation
> or decimal-point notation, whichever uses fewer characters.
This seems wrong:
(format "%g" 3.0) ⇒ "3", but
(format "%f" 3.0) ⇒ "3.000000", and
(format "%e" 3.0) ⇒ "3.000000e+00", so %g is neither %f nor %e.
> The # flag means to use an alternate display form [...]
> for %e, %f, and %g, it causes a decimal point to be included even if
> the precision is zero.
This seems incomplete:
(format "%#.5g" 3) ⇒ "3.0000", while
(format "%.5g" 3) ⇒ "3", so # doesn't just cause changes when the precision is 0.
> For %e, %f, and %g sequences, the number after the "." in the
> precision specifier says how many decimal places to show
This seems wrong, too:
(format "%.5g" 3.0) ⇒ "3", not "3.00000"
(format "%.5g" 3.1) ⇒ "3.1", not "3.10000"
Similar problems seem to exist in the actual documentation. On a related note, is there a way to get a shortest representation of a number? Something like %g, but without exponents.
Thanks!
Clément.
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#25557: Documentation of format doesn't describe "g" accurately
2017-01-27 22:05 bug#25557: Documentation of format doesn't describe "g" accurately Clément Pit--Claudel
@ 2017-01-28 8:37 ` Eli Zaretskii
2017-01-28 15:04 ` Clément Pit--Claudel
0 siblings, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2017-01-28 8:37 UTC (permalink / raw)
To: Clément Pit--Claudel; +Cc: 25557-done
> From: Clément Pit--Claudel <clement.pitclaudel@live.com>
> Date: Fri, 27 Jan 2017 17:05:28 -0500
>
> There seems to be a few issues in the docstring of `format':
>
> > %g means print a number in exponential notation
> > or decimal-point notation, whichever uses fewer characters.
>
> This seems wrong:
>
> (format "%g" 3.0) ⇒ "3", but
> (format "%f" 3.0) ⇒ "3.000000", and
> (format "%e" 3.0) ⇒ "3.000000e+00", so %g is neither %f nor %e.
Fixed.
> > The # flag means to use an alternate display form [...]
> > for %e, %f, and %g, it causes a decimal point to be included even if
> > the precision is zero.
>
> This seems incomplete:
>
> (format "%#.5g" 3) ⇒ "3.0000", while
> (format "%.5g" 3) ⇒ "3", so # doesn't just cause changes when the precision is 0.
I don't understand what you are trying to say (nor the significance of
the '.' flag in the example). '#' forces %g to leave the trailing
zeros after the decimal, so I added that -- is that what you wanted to
say?
> > For %e, %f, and %g sequences, the number after the "." in the
> > precision specifier says how many decimal places to show
>
> This seems wrong, too:
>
> (format "%.5g" 3.0) ⇒ "3", not "3.00000"
> (format "%.5g" 3.1) ⇒ "3.1", not "3.10000"
Fixed.
> Similar problems seem to exist in the actual documentation.
If you mean the ELisp manual, I fixed that as well.
> On a related note, is there a way to get a shortest representation of a number? Something like %g, but without exponents.
Sorry, I don't understand the question. How can you represent an
arbitrary number without exponents at all, except by %f?
Anyway, thanks; I'm marking this bug done.
^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#25557: Documentation of format doesn't describe "g" accurately
2017-01-28 8:37 ` Eli Zaretskii
@ 2017-01-28 15:04 ` Clément Pit--Claudel
2017-01-28 15:23 ` Eli Zaretskii
0 siblings, 1 reply; 13+ messages in thread
From: Clément Pit--Claudel @ 2017-01-28 15:04 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 25557-done
[-- Attachment #1.1: Type: text/plain, Size: 1264 bytes --]
On 2017-01-28 03:37, Eli Zaretskii wrote:
>> …
> Fixed.
>> …
>
> I don't understand what you are trying to say (nor the significance of
> the '.' flag in the example). '#' forces %g to leave the trailing
> zeros after the decimal, so I added that -- is that what you wanted to
> say?
>
>> …
> Fixed.
>
>> Similar problems seem to exist in the actual documentation.
> If you mean the ELisp manual, I fixed that as well.
Thanks a lot! My comment about '#' was that the description of '#' suggested that it would only change things when the precision is 0 (which wasn't true).
>> On a related note, is there a way to get a shortest representation of a number? Something like %g, but without exponents.
>
> Sorry, I don't understand the question. How can you represent an
> arbitrary number without exponents at all, except by %f?
I'd like something like this (with a hypothetical %q):
(format "%.3q" 3) ⇒ "3"
(format "%.3q" 3.00) ⇒ "3"
(format "%.3q" 3.30) ⇒ "3.3"
(format "%.3q" 3.05) ⇒ "3.05"
(format "%.3q" 3.352) ⇒ "3.35"
(format "%.3q" 3100000) ⇒ "3100000"
This is in fact just the same as 'g', except for the last entry (%g produces "3.1e+06"). Is this achievable?
Thanks!
Clément.
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#25557: Documentation of format doesn't describe "g" accurately
2017-01-28 15:04 ` Clément Pit--Claudel
@ 2017-01-28 15:23 ` Eli Zaretskii
2017-01-28 15:45 ` Clément Pit--Claudel
0 siblings, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2017-01-28 15:23 UTC (permalink / raw)
To: Clément Pit--Claudel; +Cc: 25557
> Cc: 25557-done@debbugs.gnu.org
> From: Clément Pit--Claudel <clement.pitclaudel@live.com>
> Date: Sat, 28 Jan 2017 10:04:33 -0500
>
> >> On a related note, is there a way to get a shortest representation of a number? Something like %g, but without exponents.
> >
> > Sorry, I don't understand the question. How can you represent an
> > arbitrary number without exponents at all, except by %f?
>
> I'd like something like this (with a hypothetical %q):
>
> (format "%.3q" 3) ⇒ "3"
> (format "%.3q" 3.00) ⇒ "3"
> (format "%.3q" 3.30) ⇒ "3.3"
> (format "%.3q" 3.05) ⇒ "3.05"
> (format "%.3q" 3.352) ⇒ "3.35"
> (format "%.3q" 3100000) ⇒ "3100000"
>
> This is in fact just the same as 'g', except for the last entry (%g produces "3.1e+06"). Is this achievable?
Yes, if you use "%.7g". In general, use "%.Ng" if you want up to N
digits in the printed representation.
Does that answer your question?
^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#25557: Documentation of format doesn't describe "g" accurately
2017-01-28 15:23 ` Eli Zaretskii
@ 2017-01-28 15:45 ` Clément Pit--Claudel
2017-01-28 16:01 ` Eli Zaretskii
0 siblings, 1 reply; 13+ messages in thread
From: Clément Pit--Claudel @ 2017-01-28 15:45 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 25557
[-- Attachment #1.1: Type: text/plain, Size: 1340 bytes --]
On 2017-01-28 10:23, Eli Zaretskii wrote:
>> Cc: 25557-done@debbugs.gnu.org
>> From: Clément Pit--Claudel <clement.pitclaudel@live.com>
>> Date: Sat, 28 Jan 2017 10:04:33 -0500
>>
>>>> On a related note, is there a way to get a shortest representation of a number? Something like %g, but without exponents.
>>>
>>> Sorry, I don't understand the question. How can you represent an
>>> arbitrary number without exponents at all, except by %f?
>>
>> I'd like something like this (with a hypothetical %q):
>>
>> (format "%.3q" 3) ⇒ "3"
>> (format "%.3q" 3.00) ⇒ "3"
>> (format "%.3q" 3.30) ⇒ "3.3"
>> (format "%.3q" 3.05) ⇒ "3.05"
>> (format "%.3q" 3.352) ⇒ "3.35"
>> (format "%.3q" 3100000) ⇒ "3100000"
>>
>> This is in fact just the same as 'g', except for the last entry (%g produces "3.1e+06"). Is this achievable?
>
> Yes, if you use "%.7g". In general, use "%.Ng" if you want up to N
> digits in the printed representation.
>
> Does that answer your question?
Almost: though this works for the last example, it breaks the one before the last (I'm looking for a format specifier that would constrain the number of decimals, not the number of digits, so that (format "%.3q" 30.352) would produce "30.35" — maybe all these examples should have had %.2q instead of %.3q, in fact).
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#25557: Documentation of format doesn't describe "g" accurately
2017-01-28 15:45 ` Clément Pit--Claudel
@ 2017-01-28 16:01 ` Eli Zaretskii
2017-01-28 16:18 ` Clément Pit--Claudel
0 siblings, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2017-01-28 16:01 UTC (permalink / raw)
To: Clément Pit--Claudel; +Cc: 25557
> Cc: 25557@debbugs.gnu.org
> From: Clément Pit--Claudel <clement.pitclaudel@live.com>
> Date: Sat, 28 Jan 2017 10:45:09 -0500
>
> >> I'd like something like this (with a hypothetical %q):
> >>
> >> (format "%.3q" 3) ⇒ "3"
> >> (format "%.3q" 3.00) ⇒ "3"
> >> (format "%.3q" 3.30) ⇒ "3.3"
> >> (format "%.3q" 3.05) ⇒ "3.05"
> >> (format "%.3q" 3.352) ⇒ "3.35"
> >> (format "%.3q" 3100000) ⇒ "3100000"
> >>
> >> This is in fact just the same as 'g', except for the last entry (%g produces "3.1e+06"). Is this achievable?
> >
> > Yes, if you use "%.7g". In general, use "%.Ng" if you want up to N
> > digits in the printed representation.
> >
> > Does that answer your question?
>
> Almost: though this works for the last example, it breaks the one before the last (I'm looking for a format specifier that would constrain the number of decimals, not the number of digits, so that (format "%.3q" 30.352) would produce "30.35" — maybe all these examples should have had %.2q instead of %.3q, in fact).
Then maybe you want %.2f?
If not, then perhaps you should explain what are you trying to
accomplish? Why is it important to see 3.35 when the value is 3.352,
but see all the trailing zeros for 3100000? It sounds like a
contradiction to me.
IME, the most general format is %g, I always use %.Ng when I need N
significant digits no matter what the magnitude of the value, and I
never have any problems.
^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#25557: Documentation of format doesn't describe "g" accurately
2017-01-28 16:01 ` Eli Zaretskii
@ 2017-01-28 16:18 ` Clément Pit--Claudel
2017-01-28 16:25 ` Eli Zaretskii
0 siblings, 1 reply; 13+ messages in thread
From: Clément Pit--Claudel @ 2017-01-28 16:18 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 25557
[-- Attachment #1.1: Type: text/plain, Size: 1909 bytes --]
On 2017-01-28 11:01, Eli Zaretskii wrote:
>> Cc: 25557@debbugs.gnu.org
>> From: Clément Pit--Claudel <clement.pitclaudel@live.com>
>> Date: Sat, 28 Jan 2017 10:45:09 -0500
>>
>>>> I'd like something like this (with a hypothetical %q):
>>>>
>>>> (format "%.3q" 3) ⇒ "3"
>>>> (format "%.3q" 3.00) ⇒ "3"
>>>> (format "%.3q" 3.30) ⇒ "3.3"
>>>> (format "%.3q" 3.05) ⇒ "3.05"
>>>> (format "%.3q" 3.352) ⇒ "3.35"
>>>> (format "%.3q" 3100000) ⇒ "3100000"
>>>>
>>>> This is in fact just the same as 'g', except for the last entry (%g produces "3.1e+06"). Is this achievable?
>>>
>>> Yes, if you use "%.7g". In general, use "%.Ng" if you want up to N
>>> digits in the printed representation.
>>>
>>> Does that answer your question?
>>
>> Almost: though this works for the last example, it breaks the one before the last (I'm looking for a format specifier that would constrain the number of decimals, not the number of digits, so that (format "%.3q" 30.352) would produce "30.35" — maybe all these examples should have had %.2q instead of %.3q, in fact).
>
> Then maybe you want %.2f?
No, that always prints decimals.
> If not, then perhaps you should explain what are you trying to
> accomplish? Why is it important to see 3.35 when the value is 3.352,
> but see all the trailing zeros for 3100000? It sounds like a
> contradiction to me.
I'm trying to get the shortest representation of a decimal number, rounded to .01, not using scientific/exponential notation. I'm using values computed in ELisp to produce CSS style sheets, which until recently didn't allow for exponential notation. I'd like these stylesheets to be readable, so 100% is better 100.00%, and 3.35em is better than 3.35004em. If my code is fed a value of 5000px, I don't want it converted to 5e+3px, because many browsers don't know how to parse that.
Thanks!
Clément.
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#25557: Documentation of format doesn't describe "g" accurately
2017-01-28 16:18 ` Clément Pit--Claudel
@ 2017-01-28 16:25 ` Eli Zaretskii
2017-01-28 19:14 ` Clément Pit--Claudel
0 siblings, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2017-01-28 16:25 UTC (permalink / raw)
To: Clément Pit--Claudel; +Cc: 25557
> Cc: 25557@debbugs.gnu.org
> From: Clément Pit--Claudel <clement.pitclaudel@live.com>
> Date: Sat, 28 Jan 2017 11:18:44 -0500
>
> I'm trying to get the shortest representation of a decimal number, rounded to .01, not using scientific/exponential notation. I'm using values computed in ELisp to produce CSS style sheets, which until recently didn't allow for exponential notation. I'd like these stylesheets to be readable, so 100% is better 100.00%, and 3.35em is better than 3.35004em. If my code is fed a value of 5000px, I don't want it converted to 5e+3px, because many browsers don't know how to parse that.
Then I think you want to use %d for integral values and %.2f for the
rest.
^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#25557: Documentation of format doesn't describe "g" accurately
2017-01-28 16:25 ` Eli Zaretskii
@ 2017-01-28 19:14 ` Clément Pit--Claudel
2017-01-28 19:31 ` Eli Zaretskii
0 siblings, 1 reply; 13+ messages in thread
From: Clément Pit--Claudel @ 2017-01-28 19:14 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 25557
[-- Attachment #1.1: Type: text/plain, Size: 1014 bytes --]
On 2017-01-28 11:25, Eli Zaretskii wrote:
>> Cc: 25557@debbugs.gnu.org
>> From: Clément Pit--Claudel <clement.pitclaudel@live.com>
>> Date: Sat, 28 Jan 2017 11:18:44 -0500
>>
>> I'm trying to get the shortest representation of a decimal number, rounded to .01, not using scientific/exponential notation. I'm using values computed in ELisp to produce CSS style sheets, which until recently didn't allow for exponential notation. I'd like these stylesheets to be readable, so 100% is better 100.00%, and 3.35em is better than 3.35004em. If my code is fed a value of 5000px, I don't want it converted to 5e+3px, because many browsers don't know how to parse that.
>
> Then I think you want to use %d for integral values and %.2f for the
> rest.
No, that still won't do: it wouldn't format 3.0 as "3", if I understand correctly.
But I also think this is a minor matter, and there are many more pressing problems and exciting areas :) Thanks for your help and patience, Eli!
Cheers,
Clément.
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#25557: Documentation of format doesn't describe "g" accurately
2017-01-28 19:14 ` Clément Pit--Claudel
@ 2017-01-28 19:31 ` Eli Zaretskii
2017-01-28 20:06 ` Clément Pit--Claudel
0 siblings, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2017-01-28 19:31 UTC (permalink / raw)
To: Clément Pit--Claudel; +Cc: 25557
> Cc: 25557@debbugs.gnu.org
> From: Clément Pit--Claudel <clement.pitclaudel@live.com>
> Date: Sat, 28 Jan 2017 14:14:03 -0500
>
> >> I'm trying to get the shortest representation of a decimal number, rounded to .01, not using scientific/exponential notation. I'm using values computed in ELisp to produce CSS style sheets, which until recently didn't allow for exponential notation. I'd like these stylesheets to be readable, so 100% is better 100.00%, and 3.35em is better than 3.35004em. If my code is fed a value of 5000px, I don't want it converted to 5e+3px, because many browsers don't know how to parse that.
> >
> > Then I think you want to use %d for integral values and %.2f for the
> > rest.
>
> No, that still won't do: it wouldn't format 3.0 as "3", if I understand correctly.
??? (format "%d" 3.0) => "3"
Or maybe you didn't think 3.0 was an "integral value" by my
definition? I meant by that any value VAL which yields zero when
passed through (mod VAL 1.0).
^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#25557: Documentation of format doesn't describe "g" accurately
2017-01-28 19:31 ` Eli Zaretskii
@ 2017-01-28 20:06 ` Clément Pit--Claudel
2017-01-28 20:29 ` Eli Zaretskii
0 siblings, 1 reply; 13+ messages in thread
From: Clément Pit--Claudel @ 2017-01-28 20:06 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 25557
[-- Attachment #1.1: Type: text/plain, Size: 1208 bytes --]
On 2017-01-28 14:31, Eli Zaretskii wrote:
>> Cc: 25557@debbugs.gnu.org
>> From: Clément Pit--Claudel <clement.pitclaudel@live.com>
>> Date: Sat, 28 Jan 2017 14:14:03 -0500
>>
>>>> I'm trying to get the shortest representation of a decimal number, rounded to .01, not using scientific/exponential notation. I'm using values computed in ELisp to produce CSS style sheets, which until recently didn't allow for exponential notation. I'd like these stylesheets to be readable, so 100% is better 100.00%, and 3.35em is better than 3.35004em. If my code is fed a value of 5000px, I don't want it converted to 5e+3px, because many browsers don't know how to parse that.
>>>
>>> Then I think you want to use %d for integral values and %.2f for the
>>> rest.
>>
>> No, that still won't do: it wouldn't format 3.0 as "3", if I understand correctly.
>
> ??? (format "%d" 3.0) => "3"
>
> Or maybe you didn't think 3.0 was an "integral value" by my
> definition? I meant by that any value VAL which yields zero when
> passed through (mod VAL 1.0).
Yup, I misunderstood your definition of integral value. But that still doesn't cover formatting e.g. 3.3 as "3.3" instead of "3.30", right?
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#25557: Documentation of format doesn't describe "g" accurately
2017-01-28 20:06 ` Clément Pit--Claudel
@ 2017-01-28 20:29 ` Eli Zaretskii
2017-01-28 20:45 ` Clément Pit--Claudel
0 siblings, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2017-01-28 20:29 UTC (permalink / raw)
To: Clément Pit--Claudel; +Cc: 25557
> Cc: 25557@debbugs.gnu.org
> From: Clément Pit--Claudel <clement.pitclaudel@live.com>
> Date: Sat, 28 Jan 2017 15:06:22 -0500
>
> > ??? (format "%d" 3.0) => "3"
> >
> > Or maybe you didn't think 3.0 was an "integral value" by my
> > definition? I meant by that any value VAL which yields zero when
> > passed through (mod VAL 1.0).
>
> Yup, I misunderstood your definition of integral value. But that still doesn't cover formatting e.g. 3.3 as "3.3" instead of "3.30", right?
Yes, but that cannot be a problem, since you said the browsers
supported 2 digits after the decimal.
Or you could get fancier by using %.1f for values for which
(zerop (mod (* 10 VAL) 1.0))
is non-nil.
^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#25557: Documentation of format doesn't describe "g" accurately
2017-01-28 20:29 ` Eli Zaretskii
@ 2017-01-28 20:45 ` Clément Pit--Claudel
0 siblings, 0 replies; 13+ messages in thread
From: Clément Pit--Claudel @ 2017-01-28 20:45 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 25557
[-- Attachment #1.1: Type: text/plain, Size: 843 bytes --]
On 2017-01-28 15:29, Eli Zaretskii wrote:
>> Cc: 25557@debbugs.gnu.org
>> From: Clément Pit--Claudel <clement.pitclaudel@live.com>
>> Date: Sat, 28 Jan 2017 15:06:22 -0500
>>
>>> ??? (format "%d" 3.0) => "3"
>>>
>>> Or maybe you didn't think 3.0 was an "integral value" by my
>>> definition? I meant by that any value VAL which yields zero when
>>> passed through (mod VAL 1.0).
>>
>> Yup, I misunderstood your definition of integral value. But that still doesn't cover formatting e.g. 3.3 as "3.3" instead of "3.30", right?
>
> Yes, but that cannot be a problem, since you said the browsers
> supported 2 digits after the decimal.
Indeed. It's just a readability issue.
> Or you could get fancier by using %.1f for values for which
>
> (zerop (mod (* 10 VAL) 1.0))
>
> is non-nil.
Sounds good. Thanks!
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2017-01-28 20:45 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-27 22:05 bug#25557: Documentation of format doesn't describe "g" accurately Clément Pit--Claudel
2017-01-28 8:37 ` Eli Zaretskii
2017-01-28 15:04 ` Clément Pit--Claudel
2017-01-28 15:23 ` Eli Zaretskii
2017-01-28 15:45 ` Clément Pit--Claudel
2017-01-28 16:01 ` Eli Zaretskii
2017-01-28 16:18 ` Clément Pit--Claudel
2017-01-28 16:25 ` Eli Zaretskii
2017-01-28 19:14 ` Clément Pit--Claudel
2017-01-28 19:31 ` Eli Zaretskii
2017-01-28 20:06 ` Clément Pit--Claudel
2017-01-28 20:29 ` Eli Zaretskii
2017-01-28 20:45 ` Clément Pit--Claudel
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.