Thread: Window comparator
If input 2 is at C volts and window size is W volts, the output is high when input 1 is between C-W and C+W.
So for your first example, set input 2 to 4V and window size to 1V to get a range of 3V to 5V.
For your second example, set input 2 to 1.5V and window size to 1.5V to get a range of 0V to 3V (or adjust as needed if you want the range to start at a negative voltage).