Comments and answers for "what is the real value of Mathf.infinity"
http://answers.unity.com/questions/15399/what-is-the-real-value-of-mathfinfinity.html
The latest comments and answers for the question "what is the real value of Mathf.infinity"Comment by Bunny83 on Bunny83's comment
http://answers.unity.com/comments/1156224/view.html
If you're just interested in what the underlying 32 bits look like, it's simply:
S Exponent Mantissa
--------------------------------------------------------------
0 1111 1111 000 0000 0000 0000 0000 0000 // positive infinity
1 1111 1111 000 0000 0000 0000 0000 0000 // negative infinity
Y 1111 1111 XXX XXXX XXXX XXXX XXXX XXXX // NaN where at least one "X" has to be "1"
For more information see [wikipedia][1]
[1]: https://en.wikipedia.org/wiki/IEEE_754-1985#ExamplesThu, 17 Mar 2016 05:57:36 GMTBunny83Comment by Fredex8 on Fredex8's comment
http://answers.unity.com/comments/1156215/view.html
Thanks for that. I assumed infinity would be marginally more efficient. The original script I modified for finding enemy distance however was using a value of 99999f with an explanation of //Some high number larger than the level. Since that seemed so ugly and using infinity instead seemed so obvious I wondered if there was a reason he hadn't done so. It seemed logical to me that infinity should be faster if it is treated as a concept and not an actual number but I wasn't sure.
But yes negligible difference at best. Even when I tried with 50 objects running that comparison for the first enemy in the list multiple times each second I noticed no difference. Just cleaner code though.Thu, 17 Mar 2016 05:32:18 GMTFredex8Comment by Bunny83 on Bunny83's comment
http://answers.unity.com/comments/1156193/view.html
Well, i doubt that it would make any mesurable difference. You actually have to distinguish between PositiveInfinity and NegativeInfinity. I guess that a comparison of a number, that isn't itself infinity, against infinity will be faster, as the hardware doesn't have to compare the values but only the "kind" of the float value. So if one operand is one of the two infinities and the other operand is any number it can immediately tell which one is larger. +inf > x and -inf < x where x is any number except that infinity you compare to.
Comparing float values in general should be quite fast anyways. First they would check the sign of both numbers. If one is positive and the other negative you can already tell which one is larger. Then you would compare the exponents alone. Depending on the signs the number with the larger(+) / smaller(-) exponent is the larger value. If both numbers have the same exponent we have to compare the mantissa. This could all be done with simple integer arithmetic. It might has some special cases for "0" as +0 and -0 actually are treated the same so -0 == +0 if you compare them.
For sorting / search algorithms to find the smallest / largest distance (or value in general) it's usually the best idea to use +inf / -inf as initial value. In your case 10000f might be too small in some cases. What if all values are greater than 10000? One could say you should pick a "reasonable large / small number" but it always depends on context what's reasonable. In a space game you might be dealing with distances way beyond 10000.Thu, 17 Mar 2016 04:37:43 GMTBunny83Comment by Bunny83 on Bunny83's comment
http://answers.unity.com/comments/1156188/view.html
@owen: In mathematics the result of the equation 1/x for x=0 is not defined as there is a singularity at at this point. The result could be either +inf or -inf. Apart from that infinity does never have an exact value. That's why 1/x for x=+inf is actually "0". For example (+inf) + (-inf) also isn't defined because infinity doesn't have an exact value. Performing that calculation will lead a NaN. As i said above the IEEE format invented the signed "0" to handle the singularity at 0. In mathematics you can inspect the limit of 1/x when approaching 0 from either side:
lim (1/x) = +inf
x-->+0
lim (1/x) = -inf
x-->-0Thu, 17 Mar 2016 04:16:24 GMTBunny83Comment by Owen-Reynolds on Owen-Reynolds's comment
http://answers.unity.com/comments/1156134/view.html
Well, in formal mathematics, depending, infinity is a perfectly good numerical value. It's infinity. The version I learned was _countable_ infinity (but I had to google to remember this.)
1/0=infinity and infinity+1=infinity are perfectly fine equations. There are even proofs showing that infinity-squared is infinity, but 2 to the power of infinity is a larger, more powerful infinity.
But, in a game or anything even close to a game, I can't think of any possible reason when that would even matter. In practice Mathf.infinity is either an error, or "largest storable number+1."Thu, 17 Mar 2016 00:48:42 GMTOwen-ReynoldsComment by Fredex8 on Fredex8's comment
http://answers.unity.com/comments/1156125/view.html
Just wondering... is comparing a float against infinity more or less efficient than comparing it against a large float.
For instance would this be more efficient if I used say 10000f on the basis that my level is never going to be that big anyway?
closestDistance = Mathf.Infinity;
if (enemyDistance < closestDistance)Thu, 17 Mar 2016 00:31:14 GMTFredex8Comment by Bunny83 on Bunny83's answer
http://answers.unity.com/comments/1156022/view.html
No, that's actually wrong. Infinity doesn't have a numerical value at all, not in computer science nor in mathematics. Infinity is a "concept" or an "idea". The IEEE floating point format has [several non number states / values][1] which indicate a special value. This includes +inf, -inf and NaN.
float.MaxValue is the actual highest value that can be represented with a float. A mathematical operation that would somehow increase that value is usually "rounded" to infinity. So the standard usually rounds to +/- inf when the number gets too large / small.
The floating point format can work with the infinity concept in a logical way, not really in a mathematical way. For example in mathematics 1/0 is not defined. You can take the limit of 1/x for x approaching 0 either from left(+) or right(-) which will lead to either +inf or -inf. The IEEE standard has solved that "problem" by introducing a "signed zero". So for example (+0)/-1 = (-0) and (-0)/-1 = (+0). However things like (inf / inf) isn't defined and will lead to a NaN (Not a Number) same happens with (0*inf). However this does work: (1/+inf) == (+0).
[1]: https://en.wikipedia.org/wiki/IEEE_754-1985#Representation_of_non-numbersWed, 16 Mar 2016 19:40:10 GMTBunny83Answer by weatxyz
http://answers.unity.com/answers/1155896/view.html
Looks like this post is old, but figured I'd add to this so people know exactly what Infinity is.
Infinity is the highest value that a floating point number can represent. Floating points are a little weird and complicated, but the formulas in the other posts calculate the highest possible value of a floating point number. float.MaxValue should actually be the same as Mathf.Infinity, but someone can correct me if I'm wrong.Wed, 16 Mar 2016 17:47:34 GMTweatxyzComment by Horsman on Horsman's answer
http://answers.unity.com/comments/70682/view.html
You see able to do this, as you suggest.Mon, 19 Apr 2010 11:13:30 GMTHorsmanAnswer by Ashkan_gc
http://answers.unity.com/answers/15461/view.html
<p>ok the answer is
the infinity number is a constant representing the infinity and it's defined in the design of the floating point calculation hardware and is one of the many numbers that can be created using 32 bits. it's a normal 32 bit series of number but computer knows about it and knows it's infinity. in some computers infinity related calculations are software emulated but in most machines it's done in hardware. in high level languages compiler itself handles it but in older languages like see it's simply a macro and you really can assign it to a variable in assembly but when you do calculations on it the computer will produce correct results so infinity+1 = infinity. be careful it's not possible to check
if (a == float.posetiveInfinity) you should use functions like isInfinity to check for that.
when i said compiler handles it i meant that there are constant in the language itself that represent the infinity and -infinity and nan numbers so you don't need to know the set of bits that they mean INF or -INF. for having negative zero you can just type -0.
don't worry about infinity because you can not assign it using numeric literals and there is not any way to get infinity as a result from a+b :)</p>Mon, 19 Apr 2010 11:08:39 GMTAshkan_gcComment by Ashkan_gc on Ashkan_gc's answer
http://answers.unity.com/comments/70678/view.html
i did not try to solve a problem. i know that it can not be assigned but i had a challenging talk with one of my friends about it. i told him that it should be a set of bits like a normal float and a number that is larger than maxvalue of floats. thank you! i will read more in MSDNMon, 19 Apr 2010 10:02:07 GMTAshkan_gcComment by KvanteTore on KvanteTore's answer
http://answers.unity.com/comments/70647/view.html
See http://en.wikipedia.org/wiki/Floating_point_number#Infinities for a reference to how floating point numbers represent infinities.Sun, 18 Apr 2010 16:30:16 GMTKvanteToreAnswer by duck
http://answers.unity.com/answers/15405/view.html
<p>As far as I'm aware, Mathf.Infinity simply <em>doesn't have</em> a "normal" numerical equivalent, so no - it's not possible to assign it using a numeric literal. </p>
<p>You can directly assign it to a variable using the Mathf.Infinity constant, or you can have it returned as a result of by dividing by zero, or by exceeding <a href="http://msdn.microsoft.com/en-us/library/system.single.maxvalue.aspx" rel="nofollow">float.MaxValue</a> in an operation, however you can't subsequently subtract from this value to return to normal numeric values.</p>
<p>I can't really understand why you'd want to try and equate it with a real number, because then by definition it would not be infinity, it would be that number! I'm not sure whether you're trying to solve a particular problem, but it doesn't make sense to use anything other than the actual Infinity constant that is already provided.</p>
<p>Mathf.Infinity takes its value directly from <a href="http://msdn.microsoft.com/en-us/library/system.single.positiveinfinity%28v=VS.80%29.aspx" rel="nofollow">float.PositiveInfinity</a> which can be looked up in the MSDN reference. </p>
<p>PositiveInfinity is one of three "special values" that can be assigned to a float variable, in addition to the normal numeric range of values. </p>
<p>The other values are <a href="http://msdn.microsoft.com/en-us/library/system.single.negativeinfinity.aspx" rel="nofollow">NegativeInfinity</a> and <a href="http://msdn.microsoft.com/en-us/library/system.single.nan.aspx" rel="nofollow">Not a Number (NaN)</a> (these also do not have a real numeric value equivalent!).</p>Sun, 18 Apr 2010 16:11:07 GMTduckAnswer by matyicsapo
http://answers.unity.com/answers/15400/view.html
<p>visual c# says: 3.402823 * Mathf.Pow(10, 38)<br>
which unity too can handle as a number</p>
<p>unity regards this as inifinity: 3.402823 * Mathf.Pow(10, 39)<br>
(both using javascript or c#)</p>
<p>tried adding and subtracting ones from both but i couldn't get to infinity nor could i get away from it </p>
<p>(3.402823 * Mathf.Pow(10, 39)) - (3.402823 * Mathf.Pow(10, 38))<br>
is still infinity</p>
<p>so i assume you could use this number: 3.402823 * Mathf.Pow(10, 38)</p>Sun, 18 Apr 2010 14:36:13 GMTmatyicsapo