Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

d language
methods
communitycreator
is_in_range()

What is the is_in_range() method in D language?

NDUKWE CHIDERA K.

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The is_in_range() method checks if the provided value is found in a range. This range contains the maximum and minimum values, called limits. The limits may or may not be part of the range. If a value searched for can be found in the said range, the function returns an integer value of 1; otherwise, 0 is returned.

Syntax

is_in_range(search_value, max_min_of_range,bounds)

Parameters

  • search_value: Check the provided range to find this parameter, the search_value.

  • max_min_of_range: These are the maximum and minimum values of a range. They define the range.

  • bounds: This is the boundary parameter. Here, we indicate if the range’s maximum and minimum values should be part of the range or not. We can either use:

    • "[]": This is the default and entails that both max and min limits should be part of the range.
    • "[)": This indicates that only the min limit is excluded from the range.
    • "(]": This indicates that only the max limit be excluded from the range.
    • "()": This indicates that both max and min limits be excluded from the range.

Return value

  • The return value is an integer 1 if search_value is in range, and it is 0 if not.
include std/search.e
atom result1, result2, result3, result4
puts(1,"0 means false and 1 true in the following result sets")
result1 = is_in_range(2, {30,50})
result2 = is_in_range(200, {100,200}, "()")
result3 = is_in_range(90, {80,90}, "(]")
result4 = is_in_range(100, {100,200}, "[)")
printf(1,"\n %d", result1)
printf(1, "\n %d", result2)
printf(1, "\n %d", result3)
printf(1, "\n %d", result4)
Using the is_in_range() function

Explanation

  • Line 1: We import the needed library into our code.

  • Line 3: We declare atom variables to hold our output.

  • Lines 5–8: We perform some is_in_range() operations, storing the outcome in the result1, result2, result3, and result4 variables.

  • Lines 9–12: We print the values of variables result1, result2, result3, and result4 to the display.

RELATED TAGS

d language
methods
communitycreator
is_in_range()

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring