Hello everyone! Some days ago I noticed one very useful trick in C++. It works in GNU. I think it will work in VS too. Many coders use macro "#define INF 1000000007", as very large number, larger then possible answer. I notice that instead of writing it, we can write INFINITY and it will the maximal of current type. For example:
ll ans = INFINITY; //long_long_max
if (smth < INFINITY) //int_max by default
if (smth < (long long)INFINITY) //long_long_max
I have never seen it in codes. Maybe for someones it will be useful.
It's not so useful. For example long long answer = INFINITY; if (answer == INFINITY) // answer != INFINITY
Yes, in this case it will not work. But it is possible to write
And it will work correctly.
That is not really useful because you usually want to have INFINITY/2 and not INFINITY itself, since any addition will overflow type. In other words you really don't want inequalities INF+5<INF to be correct.
I use
(1 << 30)
forint
. And(1ll << 60)
forlong long
type.As Shtrix stated too , it's not really useful because you simply can not do any addition to the value correctly , but if you insist on using this , I'd choose the safer way :