"exclusive" 和 "inclusive" 在描述数字范围时的含义是什么?
What is the meaning of "exclusive" and "inclusive" when describing number ranges?
简单的问题,但是,在提到数字范围时,我看到了排他性和包容性。
例如,这是算法书中的一行:
The following function prints the powers of 2 from 1 through n (inclusive).
这是什么意思?什么使数字范围包含或不包含?
The following function prints the powers of 2 from 1 through n (inclusive).
这意味着该函数将计算 2^i
,其中 i = 1, 2, ..., n
,换句话说,i
的值可以从 1 到 ,包括 [=36] =] 值 n
。即 n 是 Included in Inclusive
另一方面,如果您的书说:
The following function prints the powers of 2 from 1 through n (exclusive).
这意味着 i = 1, 2, ..., n-1
,即 i
最多可以取 n-1 个值,但 不 包括 n
,这意味着 i = n-1
是它可以 have.i 的最高值。e n 是 excluded in 独家.
在计算机科学中,inclusive/exclusive 不适用于算法,但适用于 数字范围(更具体地说,适用于范围的端点):
1 through 10 (inclusive)
1 2 3 4 5 6 7 8 9 10
1 through 10 (exclusive)
1 2 3 4 5 6 7 8 9
在数学中,上面的 2 个范围是:
[1, 10]
[1, 10)
你可以轻松记住它:
- 包括五个 - 包括最后一个数字
- Exclu五个 - Exclu最后一个数
简单来说,inclusive就是在n
个数以内,exclusive就是在n
个数以内和之外。
注意:每个论点都应标明其“包容性”/“参与性”
# 1 (inclusive) through 5 (inclusive)
1 <= x <= 5 == [1, 2, 3, 4, 5]
# 1 (inclusive) through 5 (exclusive)
1 <= x < 5 == [1, 2, 3, 4]
# 1 (exclusive) through 5 (inclusive)
1 < x <= 5 == [2, 3, 4, 5]
# 1 (exclusive) through 5 (exclusive)
1 < x < 5 == [2, 3, 4]
n 的值包括 2 和 5 [2,5]
包括两个数字以防排他,只包括第一个
编程术语 n>=2 && n<=5
n 的值不包括 2 和 5 [2,5)
n>=2 && n<5
简单的问题,但是,在提到数字范围时,我看到了排他性和包容性。
例如,这是算法书中的一行:
The following function prints the powers of 2 from 1 through n (inclusive).
这是什么意思?什么使数字范围包含或不包含?
The following function prints the powers of 2 from 1 through n (inclusive).
这意味着该函数将计算 2^i
,其中 i = 1, 2, ..., n
,换句话说,i
的值可以从 1 到 ,包括 [=36] =] 值 n
。即 n 是 Included in Inclusive
另一方面,如果您的书说:
The following function prints the powers of 2 from 1 through n (exclusive).
这意味着 i = 1, 2, ..., n-1
,即 i
最多可以取 n-1 个值,但 不 包括 n
,这意味着 i = n-1
是它可以 have.i 的最高值。e n 是 excluded in 独家.
在计算机科学中,inclusive/exclusive 不适用于算法,但适用于 数字范围(更具体地说,适用于范围的端点):
1 through 10 (inclusive)
1 2 3 4 5 6 7 8 9 10
1 through 10 (exclusive)
1 2 3 4 5 6 7 8 9
在数学中,上面的 2 个范围是:
[1, 10]
[1, 10)
你可以轻松记住它:
- 包括五个 - 包括最后一个数字
- Exclu五个 - Exclu最后一个数
简单来说,inclusive就是在n
个数以内,exclusive就是在n
个数以内和之外。
注意:每个论点都应标明其“包容性”/“参与性”
# 1 (inclusive) through 5 (inclusive)
1 <= x <= 5 == [1, 2, 3, 4, 5]
# 1 (inclusive) through 5 (exclusive)
1 <= x < 5 == [1, 2, 3, 4]
# 1 (exclusive) through 5 (inclusive)
1 < x <= 5 == [2, 3, 4, 5]
# 1 (exclusive) through 5 (exclusive)
1 < x < 5 == [2, 3, 4]
n 的值包括 2 和 5 [2,5] 包括两个数字以防排他,只包括第一个 编程术语 n>=2 && n<=5
n 的值不包括 2 和 5 [2,5) n>=2 && n<5