What does ‘between’ and ‘in range’ mean in the world of numeric types?

Given is an integer with the value 5. Given is a range with start and end values of 2 and 5. So is the integer 5 now between the range? What should a ‘InBetween()’ method return and which one is the correct representation of ‘between’:

int val = 5

if(val >= 2 && val <= 5) // would return true

if(val > 2 && val < 5) // would return false

1

There is no clear answer to this as “between” can be interpreted in lots of way. I’d argue that inBetween(1, 4) should check 2, 3 but that’s just me.

There are other examples like, Random.nextInt(1,4) – does it return values 1,2,3,4; 2,3 or 2,3,4?

So most functions tend to clarify that in the documentation, for instance:


public String substring(int beginIndex, int endIndex)

Returns a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex – 1. Thus the length of the substring is endIndex-beginIndex. Examples:

 "hamburger".substring(4, 8) returns "urge"
 "smiles".substring(1, 5) returns "mile"

Parameters:

  beginIndex - the beginning index, inclusive.
  endIndex - the ending index, exclusive.

If you want to be precise, then use the common mathematical notation as described here:

So [1, 5) means the interval 1,2,3,4 (integers) or 1 to 4.999… if we’re using floats.

2

For integer types, it’s normal practice to include the specified values within the range. You would say that the range of a single standard die is between 1 and 6, not 0 and 7.

For floating point types, it varies depending on the specification of the particular project. When defining adjacent bands, it’s common to include one value, but to exclude the other.

e.g.

double value
if (value >= 0.0 && value < 2.0)
    ...
else if (value >= 2.0 && value < 5.0)
   ...

In math, there are four interval (range) specification forms, shown here with corresponding C expressions:

(a,b) ((a < x) && (x < b))
[a,b) ((a <= x) && (x < b))
(a,b] ((a < x) && (x <= b))
[a,b] ((a <= x) && (x <= b))

The idea is that ( and ) denote open ends, while [ and ] denote closed ends.

Added, based on the comment from “stakx”: An open end of an interval is one that does not include the actual endpoint. A closed end is one that does include the endpoint. For example, (3,5) is an open interval, 3 < x < 5. Neither 3 nor 5 are included. [4,6) is a half-open interval: 4 is included, 6 is not. [5,7] is a closed interval: both 5 and 7 are included.

The different forms are not that interesting for integers, as any open or half-open integer interval can be expressed as the equivalent closed interval (and vice versa, of course). They become useful for rationals and reals.

Saying “in between” is ambiguous. It doesn’t say whether the endpoints are included (i.e., is the range open or closed on either or both ends). You need to specify it more clearly, so you can say which of the four forms is intended as the specification, given the endpoints.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

What does ‘between’ and ‘in range’ mean in the world of numeric types?

Given is an integer with the value 5. Given is a range with start and end values of 2 and 5. So is the integer 5 now between the range? What should a ‘InBetween()’ method return and which one is the correct representation of ‘between’:

int val = 5

if(val >= 2 && val <= 5) // would return true

if(val > 2 && val < 5) // would return false

1

There is no clear answer to this as “between” can be interpreted in lots of way. I’d argue that inBetween(1, 4) should check 2, 3 but that’s just me.

There are other examples like, Random.nextInt(1,4) – does it return values 1,2,3,4; 2,3 or 2,3,4?

So most functions tend to clarify that in the documentation, for instance:


public String substring(int beginIndex, int endIndex)

Returns a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex – 1. Thus the length of the substring is endIndex-beginIndex. Examples:

 "hamburger".substring(4, 8) returns "urge"
 "smiles".substring(1, 5) returns "mile"

Parameters:

  beginIndex - the beginning index, inclusive.
  endIndex - the ending index, exclusive.

If you want to be precise, then use the common mathematical notation as described here:

So [1, 5) means the interval 1,2,3,4 (integers) or 1 to 4.999… if we’re using floats.

2

For integer types, it’s normal practice to include the specified values within the range. You would say that the range of a single standard die is between 1 and 6, not 0 and 7.

For floating point types, it varies depending on the specification of the particular project. When defining adjacent bands, it’s common to include one value, but to exclude the other.

e.g.

double value
if (value >= 0.0 && value < 2.0)
    ...
else if (value >= 2.0 && value < 5.0)
   ...

In math, there are four interval (range) specification forms, shown here with corresponding C expressions:

(a,b) ((a < x) && (x < b))
[a,b) ((a <= x) && (x < b))
(a,b] ((a < x) && (x <= b))
[a,b] ((a <= x) && (x <= b))

The idea is that ( and ) denote open ends, while [ and ] denote closed ends.

Added, based on the comment from “stakx”: An open end of an interval is one that does not include the actual endpoint. A closed end is one that does include the endpoint. For example, (3,5) is an open interval, 3 < x < 5. Neither 3 nor 5 are included. [4,6) is a half-open interval: 4 is included, 6 is not. [5,7] is a closed interval: both 5 and 7 are included.

The different forms are not that interesting for integers, as any open or half-open integer interval can be expressed as the equivalent closed interval (and vice versa, of course). They become useful for rationals and reals.

Saying “in between” is ambiguous. It doesn’t say whether the endpoints are included (i.e., is the range open or closed on either or both ends). You need to specify it more clearly, so you can say which of the four forms is intended as the specification, given the endpoints.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

What does ‘between’ and ‘in range’ mean in the world of numeric types?

Given is an integer with the value 5. Given is a range with start and end values of 2 and 5. So is the integer 5 now between the range? What should a ‘InBetween()’ method return and which one is the correct representation of ‘between’:

int val = 5

if(val >= 2 && val <= 5) // would return true

if(val > 2 && val < 5) // would return false

1

There is no clear answer to this as “between” can be interpreted in lots of way. I’d argue that inBetween(1, 4) should check 2, 3 but that’s just me.

There are other examples like, Random.nextInt(1,4) – does it return values 1,2,3,4; 2,3 or 2,3,4?

So most functions tend to clarify that in the documentation, for instance:


public String substring(int beginIndex, int endIndex)

Returns a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex – 1. Thus the length of the substring is endIndex-beginIndex. Examples:

 "hamburger".substring(4, 8) returns "urge"
 "smiles".substring(1, 5) returns "mile"

Parameters:

  beginIndex - the beginning index, inclusive.
  endIndex - the ending index, exclusive.

If you want to be precise, then use the common mathematical notation as described here:

So [1, 5) means the interval 1,2,3,4 (integers) or 1 to 4.999… if we’re using floats.

2

For integer types, it’s normal practice to include the specified values within the range. You would say that the range of a single standard die is between 1 and 6, not 0 and 7.

For floating point types, it varies depending on the specification of the particular project. When defining adjacent bands, it’s common to include one value, but to exclude the other.

e.g.

double value
if (value >= 0.0 && value < 2.0)
    ...
else if (value >= 2.0 && value < 5.0)
   ...

In math, there are four interval (range) specification forms, shown here with corresponding C expressions:

(a,b) ((a < x) && (x < b))
[a,b) ((a <= x) && (x < b))
(a,b] ((a < x) && (x <= b))
[a,b] ((a <= x) && (x <= b))

The idea is that ( and ) denote open ends, while [ and ] denote closed ends.

Added, based on the comment from “stakx”: An open end of an interval is one that does not include the actual endpoint. A closed end is one that does include the endpoint. For example, (3,5) is an open interval, 3 < x < 5. Neither 3 nor 5 are included. [4,6) is a half-open interval: 4 is included, 6 is not. [5,7] is a closed interval: both 5 and 7 are included.

The different forms are not that interesting for integers, as any open or half-open integer interval can be expressed as the equivalent closed interval (and vice versa, of course). They become useful for rationals and reals.

Saying “in between” is ambiguous. It doesn’t say whether the endpoints are included (i.e., is the range open or closed on either or both ends). You need to specify it more clearly, so you can say which of the four forms is intended as the specification, given the endpoints.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật