comparison runtime/doc/eval.txt @ 18080:a6d218f99ff7 v8.1.2035

patch 8.1.2035: recognizing octal numbers is confusing Commit: https://github.com/vim/vim/commit/60a8de28d11595f4df0419ece8afa7d6accc9fbd Author: Bram Moolenaar <Bram@vim.org> Date: Sun Sep 15 14:33:22 2019 +0200 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.
author Bram Moolenaar <Bram@vim.org>
date Sun, 15 Sep 2019 14:45:04 +0200
parents 8ac85adee561
children e59ff7b5d7a7
comparison
equal deleted inserted replaced
18079:c4ca2f98e7b4 18080:a6d218f99ff7
1 *eval.txt* For Vim version 8.1. Last change: 2019 Sep 10 1 *eval.txt* For Vim version 8.1. Last change: 2019 Sep 15
2 2
3 3
4 VIM REFERENCE MANUAL by Bram Moolenaar 4 VIM REFERENCE MANUAL by Bram Moolenaar
5 5
6 6
90 Number 0 --> String "0" ~ 90 Number 0 --> String "0" ~
91 Number -1 --> String "-1" ~ 91 Number -1 --> String "-1" ~
92 *octal* 92 *octal*
93 Conversion from a String to a Number is done by converting the first digits to 93 Conversion from a String to a Number is done by converting the first digits to
94 a number. Hexadecimal "0xf9", Octal "017", and Binary "0b10" numbers are 94 a number. Hexadecimal "0xf9", Octal "017", and Binary "0b10" numbers are
95 recognized. If the String doesn't start with digits, the result is zero. 95 recognized (NOTE: when using |scriptversion-4| octal is not recognized). If
96 the String doesn't start with digits, the result is zero.
96 Examples: 97 Examples:
97 String "456" --> Number 456 ~ 98 String "456" --> Number 456 ~
98 String "6bar" --> Number 6 ~ 99 String "6bar" --> Number 6 ~
99 String "foo" --> Number 0 ~ 100 String "foo" --> Number 0 ~
100 String "0xf1" --> Number 241 ~ 101 String "0xf1" --> Number 241 ~
2755 List make |List| from {pat} separated {expr} 2756 List make |List| from {pat} separated {expr}
2756 sqrt({expr}) Float square root of {expr} 2757 sqrt({expr}) Float square root of {expr}
2757 str2float({expr}) Float convert String to Float 2758 str2float({expr}) Float convert String to Float
2758 str2list({expr} [, {utf8}]) List convert each character of {expr} to 2759 str2list({expr} [, {utf8}]) List convert each character of {expr} to
2759 ASCII/UTF8 value 2760 ASCII/UTF8 value
2760 str2nr({expr} [, {base}]) Number convert String to Number 2761 str2nr({expr} [, {base} [, {quoted}]])
2762 Number convert String to Number
2761 strchars({expr} [, {skipcc}]) Number character length of the String {expr} 2763 strchars({expr} [, {skipcc}]) Number character length of the String {expr}
2762 strcharpart({str}, {start} [, {len}]) 2764 strcharpart({str}, {start} [, {len}])
2763 String {len} characters of {str} at {start} 2765 String {len} characters of {str} at {start}
2764 strdisplaywidth({expr} [, {col}]) Number display length of the String {expr} 2766 strdisplaywidth({expr} [, {col}]) Number display length of the String {expr}
2765 strftime({format} [, {time}]) String time in specified format 2767 strftime({format} [, {time}]) String time in specified format
9073 9075
9074 < Can also be used as a |method|: > 9076 < Can also be used as a |method|: >
9075 GetString()->str2list() 9077 GetString()->str2list()
9076 9078
9077 9079
9078 str2nr({expr} [, {base}]) *str2nr()* 9080 str2nr({expr} [, {base} [, {quoted}]]) *str2nr()*
9079 Convert string {expr} to a number. 9081 Convert string {expr} to a number.
9080 {base} is the conversion base, it can be 2, 8, 10 or 16. 9082 {base} is the conversion base, it can be 2, 8, 10 or 16.
9083 When {quoted} is present and non-zero then embedded single
9084 quotes are ignored, thus "1'000'000" is a million.
9081 9085
9082 When {base} is omitted base 10 is used. This also means that 9086 When {base} is omitted base 10 is used. This also means that
9083 a leading zero doesn't cause octal conversion to be used, as 9087 a leading zero doesn't cause octal conversion to be used, as
9084 with the default String to Number conversion. Example: > 9088 with the default String to Number conversion. Example: >
9085 let nr = str2nr('123') 9089 let nr = str2nr('123')
12935 work as |v:version| anymore, it can be used as a normal variable. 12939 work as |v:version| anymore, it can be used as a normal variable.
12936 Same for some obvious names as "count" and others. 12940 Same for some obvious names as "count" and others.
12937 12941
12938 Test for support with: > 12942 Test for support with: >
12939 has('vimscript-3') 12943 has('vimscript-3')
12944 <
12945 *scriptversion-4* >
12946 :scriptversion 4
12947 < Numbers with a leading zero are not recognized as octal. With the
12948 previous version you get: >
12949 echo 017 " displays 15
12950 echo 018 " displays 18
12951 < with script version 4: >
12952 echo 017 " displays 17
12953 echo 018 " displays 18
12954 < Also, it is possible to use single quotes inside numbers to make them
12955 easier to read: >
12956 echo 1'000'000
12957 < The quotes must be surrounded by digits.
12958
12959 Test for support with: >
12960 has('vimscript-4')
12940 12961
12941 ============================================================================== 12962 ==============================================================================
12942 11. No +eval feature *no-eval-feature* 12963 11. No +eval feature *no-eval-feature*
12943 12964
12944 When the |+eval| feature was disabled at compile time, none of the expression 12965 When the |+eval| feature was disabled at compile time, none of the expression