Mercurial > vim
comparison runtime/doc/eval.txt @ 20665:6ff992bf4c82 v8.2.0886
patch 8.2.0886: cannot use octal numbers in scriptversion 4
Commit: https://github.com/vim/vim/commit/c17e66c5c0acd5038f1eb3d7b3049b64bb6ea30b
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Jun 2 21:38:22 2020 +0200
patch 8.2.0886: cannot use octal numbers in scriptversion 4
Problem: Cannot use octal numbers in scriptversion 4.
Solution: Add the "0o" notation. (Ken Takata, closes https://github.com/vim/vim/issues/5304)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 02 Jun 2020 21:45:03 +0200 |
parents | 1fa0ace0ba65 |
children | 1af1d8ff2aa8 |
comparison
equal
deleted
inserted
replaced
20664:2ee305469487 | 20665:6ff992bf4c82 |
---|---|
93 Number 123 --> String "123" ~ | 93 Number 123 --> String "123" ~ |
94 Number 0 --> String "0" ~ | 94 Number 0 --> String "0" ~ |
95 Number -1 --> String "-1" ~ | 95 Number -1 --> String "-1" ~ |
96 *octal* | 96 *octal* |
97 Conversion from a String to a Number is done by converting the first digits to | 97 Conversion from a String to a Number is done by converting the first digits to |
98 a number. Hexadecimal "0xf9", Octal "017", and Binary "0b10" numbers are | 98 a number. Hexadecimal "0xf9", Octal "017" or "0o17", and Binary "0b10" |
99 recognized (NOTE: when using |scriptversion-4| octal is not recognized). If | 99 numbers are recognized (NOTE: when using |scriptversion-4| octal with a |
100 the String doesn't start with digits, the result is zero. | 100 leading "0" is not recognized). If the String doesn't start with digits, the |
101 result is zero. | |
101 Examples: | 102 Examples: |
102 String "456" --> Number 456 ~ | 103 String "456" --> Number 456 ~ |
103 String "6bar" --> Number 6 ~ | 104 String "6bar" --> Number 6 ~ |
104 String "foo" --> Number 0 ~ | 105 String "foo" --> Number 0 ~ |
105 String "0xf1" --> Number 241 ~ | 106 String "0xf1" --> Number 241 ~ |
106 String "0100" --> Number 64 ~ | 107 String "0100" --> Number 64 ~ |
108 String "0o100" --> Number 64 ~ | |
107 String "0b101" --> Number 5 ~ | 109 String "0b101" --> Number 5 ~ |
108 String "-8" --> Number -8 ~ | 110 String "-8" --> Number -8 ~ |
109 String "+8" --> Number 0 ~ | 111 String "+8" --> Number 0 ~ |
110 | 112 |
111 To force conversion from String to Number, add zero to it: > | 113 To force conversion from String to Number, add zero to it: > |
1262 ------ | 1264 ------ |
1263 number number constant *expr-number* | 1265 number number constant *expr-number* |
1264 *hex-number* *octal-number* *binary-number* | 1266 *hex-number* *octal-number* *binary-number* |
1265 | 1267 |
1266 Decimal, Hexadecimal (starting with 0x or 0X), Binary (starting with 0b or 0B) | 1268 Decimal, Hexadecimal (starting with 0x or 0X), Binary (starting with 0b or 0B) |
1267 and Octal (starting with 0). | 1269 and Octal (starting with 0, 0o or 0O). |
1268 | 1270 |
1269 *floating-point-format* | 1271 *floating-point-format* |
1270 Floating point numbers can be written in two forms: | 1272 Floating point numbers can be written in two forms: |
1271 | 1273 |
1272 [-+]{N}.{M} | 1274 [-+]{N}.{M} |
9640 with the default String to Number conversion. Example: > | 9642 with the default String to Number conversion. Example: > |
9641 let nr = str2nr('0123') | 9643 let nr = str2nr('0123') |
9642 < | 9644 < |
9643 When {base} is 16 a leading "0x" or "0X" is ignored. With a | 9645 When {base} is 16 a leading "0x" or "0X" is ignored. With a |
9644 different base the result will be zero. Similarly, when | 9646 different base the result will be zero. Similarly, when |
9645 {base} is 8 a leading "0" is ignored, and when {base} is 2 a | 9647 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when |
9646 leading "0b" or "0B" is ignored. | 9648 {base} is 2 a leading "0b" or "0B" is ignored. |
9647 Text after the number is silently ignored. | 9649 Text after the number is silently ignored. |
9648 | 9650 |
9649 Can also be used as a |method|: > | 9651 Can also be used as a |method|: > |
9650 GetText()->str2nr() | 9652 GetText()->str2nr() |
9651 | 9653 |
13591 Test for support with: > | 13593 Test for support with: > |
13592 has('vimscript-3') | 13594 has('vimscript-3') |
13593 < | 13595 < |
13594 *scriptversion-4* > | 13596 *scriptversion-4* > |
13595 :scriptversion 4 | 13597 :scriptversion 4 |
13596 < Numbers with a leading zero are not recognized as octal. With the | 13598 < Numbers with a leading zero are not recognized as octal. "0o" or "0O" |
13599 is still recognized as octal. With the | |
13597 previous version you get: > | 13600 previous version you get: > |
13598 echo 017 " displays 15 | 13601 echo 017 " displays 15 (octal) |
13599 echo 018 " displays 18 | 13602 echo 0o17 " displays 15 (octal) |
13603 echo 018 " displays 18 (decimal) | |
13600 < with script version 4: > | 13604 < with script version 4: > |
13601 echo 017 " displays 17 | 13605 echo 017 " displays 17 (decimal) |
13602 echo 018 " displays 18 | 13606 echo 0o17 " displays 15 (octal) |
13607 echo 018 " displays 18 (decimal) | |
13603 < Also, it is possible to use single quotes inside numbers to make them | 13608 < Also, it is possible to use single quotes inside numbers to make them |
13604 easier to read: > | 13609 easier to read: > |
13605 echo 1'000'000 | 13610 echo 1'000'000 |
13606 < The quotes must be surrounded by digits. | 13611 < The quotes must be surrounded by digits. |
13607 | 13612 |