On Tue 24-Jun-08 2:05am -0600, Ben Schmidt wrote:
> Unfortunately, these technical system-dependent troubles add weight to
> the argument to just use printf in Vim rather than a specialised routine.
> Or something really simple, e.g. just use %.12g and remove zeros between
> the decimal place and immediately before e or end of string.
>
> substitute(printf("%.11g",0.003333e15),
> \ '[EMAIL PROTECTED](e\|$\)','','')
This is pretty much what I'm doing, but using a format
string of "%0.*e" for scientific and "%0.*f" for normal.
Since I always do the "%0.*e", I was reluctant to rely on
"%g" format - one more thing that may vary by compilers. My
compiler's "%e" always returns 'e[+-]\d\d\d' but I handle
any reasonalbe format removing leading zeros from '\d\d\d'.
>> Please let me know if the new PG()
>> produces strange results for 1.0e-323.
> :echo PG(1.0e-323)
> 9.88131291682e-324
That's strange since, as you can see, it is Vim's printf()
returning that result - but if you have a denormalized, you
may have only a few bits representing the characteristic
(and that may expand to such a number).
>> In Vim, I can't seem to get a -0.0 result. Likewise,
>> :echo PG(-0.0)
>> 0
>
> O, at least that's an easy one. It's because you're ensuring you have a
> float by doing a:x + 0.0, and -0.0 + 0.0 gives 0.0. You have to ensure
> you do the float conversion only if it isn't a float already so you
> don't lose this precious info.
Hmm, I tried replacing:
let x = a:x + 0.0
with
let x = type(a:x) == type(0.0) ? a:x : a:x + 0.0
but that didn't printf() the -0.
--
Best regards,
Bill
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---