On 09/04/08 17:30, Bram Moolenaar wrote:
> Tony Mechelynck wrote:
[...]
>> Oh, oh.. it had started working (and&1.0e256 multiplied by itself gives
>> inf, which is correct), but ":echo&1.0e308" crashes gvim (on Linux
>> i686) with SIGSEGV.
>
> Easy to reproduce.  Turns out that this line causes it:
>
>       sprintf(tmp, format, f);
>
> Here "format" is "%f"  and "f" is your value 1e+308.  The result is an
> awful long string of numbers.  I suppose it's about 308 digits.  How big
> does "tmp" need to be to hold any result here?  I don't think %f has a
> way of specifying a maximal field width.
[...]

I suggest a third floating-point format (%g maybe, or something else if 
that is already taken) which would mean "either %f or %e depending on 
the size of the exponent" similar, IIRC, to the number output formats 
available in FORTRAN and/or BASIC. That format would be implicit when 
":echo"ing a floating-point number. (Yes, I know, Vim is neither FORTRAN 
nor BASIC, but I feel this kind of thing would be better than crashing 
or even than giving an error.)

IIRC, in FORTRAN, the G output format would give (for different values 
output under a single format) results like:

-1.234567E-123 (for a small number)
  2.25          (with spaces to the same width)
  342.5682      (with spaces for a large number but not too large)
  6.020000E+023 (for an even bigger number)
NAN            (a special case)
-INF           (another special case)

(this from what [I think that] I remember from the time I used FORTRAN 
on computers whose printers had no lowercase letters).


Best regards,
Tony.
-- 
MESKIMEN'S LAW
     There's never time to do it right, but always time to do it over.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Raspunde prin e-mail lui