Bram Moolenaar wrote:
>> g and G omit superfluos zeroes, as well as the decimal point:
>>
>> double n = 12;
>> printf("%g\n", n); // prints 12
>> printf("%#g\n", n); // prints 12.0000
>
> Vim is already using %g. For me the results are different.
In Vim, the code in vim_snprintf() (in message.c) replaces 'g' with 'f' for a
small
value like 12, so Vim does not give the result quoted above. However, "standard"
printf should do what I said (see [1]).
I am one of those who are inclined to NOT complicate the Vim source by
attending to
details of handling floating point, so I would live with the current situation.
However, it did occur to me that you might contemplate whether a config build
option
could specify if the native snprintf() should be used. Then if someone wants
"standard" printf, they could build Vim so vim_snprintf() calls the version
supplied
by their library.
Or, the code in vim_snprintf() could be made a little more complex by NOT
replacing
'g' with 'f'. I'll have a go at that if you like (needs a little care to be
sure we
won't overflow the tmp buffer).
[1] I have confirmed my claim quoted above on two current systems: Windows +
Linux.
There are also lots of references that confirm this (including a BSD manual). In
http://en.wikipedia.org/wiki/Printf the description for g,G says:
"Print a double in either normal or exponential notation, whichever is more
appropriate for its magnitude. 'g' uses lower-case letters, 'G' uses upper-case
letters. This type differs slightly from fixed-point notation in that
insignificant
zeroes to the right of the decimal point are not included. Also, the decimal
point
is not included on whole numbers."
John
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---