There is a simple hack for you. :infinity is greater than any number here. Because check the order of comparison in elixir number < atom < reference < function < port < pid < tuple < map < list < bitstring
Erlang/Elixir does not have a built-in infinity value(nor does it have a Not-a-Number value), because its floating-point arithmetic is not fully IEEE754-compliant (it predates that standard).
Depending on what you are doing, maybe you might want to look at the decimal library to allow arbitrary-precision arithmetic, with support for (both positive and negative) infinity.
This is a silly question I suspect, but… I have to ask it.
I’d assume that any finite number is great than -Infinity and less than +Infinity, then what’s the use for an entity representing it/them in code?
Ok, as @OvermindDL1 said this was for generic code.
One way I found to workaround it was to create an infinity/1 and minus_infinity/1 functions. Both of these take a number as input and return that value +/- a constant ( integer one ). That way whenever I wanted to compare x > infinity I’d write x > infinity(x).
Can I ask why you need a value for infinity in the case stated, why check if x is less than infinity, surely if it’s any numeric value it would be true. Your only interested in if x is greater than y and a valid number. As your not setting an upper range limit for y it’s just a check if x > y or am i missing something here, that check could only return true if both were valid numbers .
I can understand use in a timeout as you essentially want an indefinite wait. But in a comparison it’s pointless running a check that always returns true
I suppose in elixir you could just say x is greater than the head of y if it’s an array list etc if you just want to know if x is greater that the first number in range y that is
In elixir >/< is not “greater than”/“less than”, it’s the sorting comparison operator, so it applies to every data. It will generate a deterministic response for any two terms no matter what. It might not be what you expect (as in the case for DateTime values) but it will be what you expect for numbers and :infinity.
Thanks for clarifying I was talking in terms of comparing numbers, a number is finite and therefore always less than infinity was my logic so checking if a numeric value is less than infinity is sort of pointless as it would always be true in all cases
I understand an atom for infinity makes sense for timeouts, just that the original question asked in this post seems to be asking about mathematical comparisons. Still wasnt sure if the poster needs to check value x is less than infinity or just within range y, or needs infinity as a kind of wait forever. Do you get what I mean, the context is a little vague. Just was interested to know why he needed that check, and what does it solve.
Understanding these ways to compare are super helpful though
If you want to get mathematical about it the space is a almost-well ordered adjoint space (https://en.m.wikipedia.org/wiki/Axiom_of_adjunction) which happens to contain N and R (it’s not perfectly well ordered because for example (1 !== 1.0) && !( 1 < 1.0 || 1 > 1.0))