Hi all,

Recently, there was some work done on defining how to handle converting
numeric literals in vim script to C integers -- basically, clamp to the
extremes of the datatype.  If it would exceed the max/min value, then
just treat it as the max/min value.

However, there's nothing defining how arithmetic behaves when it would
exceed the range of the datatype.  The only information in the help is:

  Number                A 32 or 64 bit signed number.  |expr-number| *Number*
                64-bit Numbers are available only when compiled with the
                |+num64| feature.

Now, in C signed over/underflow is undefined behavior.  If you're "lucky",
the implementation will wrap but it could just as well optimize the code
under the assumption that the code can't over/underflow.

Currently, Vim runs afoul of undefined behavior as can easily be seen
with a -fsanitize=undefined build by running

  if has('num64')
    echo float2nr(pow(2, 62)) * 2
  else
    echo float2nr(pow(2, 30)) * 2
  endif

It would be nice for there to be defined behavior here for the user,
instead of exposing them to the whims of the compiler implementation.

Cheers,
-- 
James
GPG Key: 4096R/91BF BF4D 6956 BD5D F7B7  2D23 DFE6 91AE 331B A3DB

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui