mirror of
https://github.com/vim/vim.git
synced 2025-09-23 03:43:49 -04:00
patch 8.1.2035: recognizing octal numbers is confusing
Problem: Recognizing octal numbers is confusing. Solution: Introduce scriptversion 4: do not use octal and allow for single quote inside numbers.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
*eval.txt* For Vim version 8.1. Last change: 2019 Sep 10
|
||||
*eval.txt* For Vim version 8.1. Last change: 2019 Sep 15
|
||||
|
||||
|
||||
VIM REFERENCE MANUAL by Bram Moolenaar
|
||||
@@ -92,7 +92,8 @@ the Number. Examples:
|
||||
*octal*
|
||||
Conversion from a String to a Number is done by converting the first digits to
|
||||
a number. Hexadecimal "0xf9", Octal "017", and Binary "0b10" numbers are
|
||||
recognized. If the String doesn't start with digits, the result is zero.
|
||||
recognized (NOTE: when using |scriptversion-4| octal is not recognized). If
|
||||
the String doesn't start with digits, the result is zero.
|
||||
Examples:
|
||||
String "456" --> Number 456 ~
|
||||
String "6bar" --> Number 6 ~
|
||||
@@ -2757,7 +2758,8 @@ sqrt({expr}) Float square root of {expr}
|
||||
str2float({expr}) Float convert String to Float
|
||||
str2list({expr} [, {utf8}]) List convert each character of {expr} to
|
||||
ASCII/UTF8 value
|
||||
str2nr({expr} [, {base}]) Number convert String to Number
|
||||
str2nr({expr} [, {base} [, {quoted}]])
|
||||
Number convert String to Number
|
||||
strchars({expr} [, {skipcc}]) Number character length of the String {expr}
|
||||
strcharpart({str}, {start} [, {len}])
|
||||
String {len} characters of {str} at {start}
|
||||
@@ -9075,9 +9077,11 @@ str2list({expr} [, {utf8}]) *str2list()*
|
||||
GetString()->str2list()
|
||||
|
||||
|
||||
str2nr({expr} [, {base}]) *str2nr()*
|
||||
str2nr({expr} [, {base} [, {quoted}]]) *str2nr()*
|
||||
Convert string {expr} to a number.
|
||||
{base} is the conversion base, it can be 2, 8, 10 or 16.
|
||||
When {quoted} is present and non-zero then embedded single
|
||||
quotes are ignored, thus "1'000'000" is a million.
|
||||
|
||||
When {base} is omitted base 10 is used. This also means that
|
||||
a leading zero doesn't cause octal conversion to be used, as
|
||||
@@ -12937,6 +12941,23 @@ instead of failing in mysterious ways.
|
||||
|
||||
Test for support with: >
|
||||
has('vimscript-3')
|
||||
<
|
||||
*scriptversion-4* >
|
||||
:scriptversion 4
|
||||
< Numbers with a leading zero are not recognized as octal. With the
|
||||
previous version you get: >
|
||||
echo 017 " displays 15
|
||||
echo 018 " displays 18
|
||||
< with script version 4: >
|
||||
echo 017 " displays 17
|
||||
echo 018 " displays 18
|
||||
< Also, it is possible to use single quotes inside numbers to make them
|
||||
easier to read: >
|
||||
echo 1'000'000
|
||||
< The quotes must be surrounded by digits.
|
||||
|
||||
Test for support with: >
|
||||
has('vimscript-4')
|
||||
|
||||
==============================================================================
|
||||
11. No +eval feature *no-eval-feature*
|
||||
|
Reference in New Issue
Block a user