All negative numbers range

Hi anyone reading this, I'm trying to create a range of all negative numbers in a way that looks like math interval notation. Is there a way to make rust code do this (-∞, 0)?

There are uncountably many real numbers in the range (-∞, 0). It would be impossible for a computer to even store most of them, let alone enumerate them. If you're just doing interval operations like union and intersection, there may be a crate to help with that.

1 Like

(..0) is a range expression (type RangeTo) that represents all numbers strictly less than zero.

7 Likes

Thank you for your response. I actually tried that but it didn't work, well it turned out that I was running rustc 1.79.0 which doesn't implement exclusive range patterns. So I updated to 1.80.1 and it worked. Thanks again!

You didn't mention this was in a pattern matching context. In this case, however, why aren't you simply writing x < 0?

Good point, I probably should've mentioned that haha. But two reasons:

  1. I was just curious if there was a way to make a negative number range using math interval notation
  2. At the time I posted this, I didn't know about match guards

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.