I want to know what is the real value of mathf.infinity? i want to know what number unity uses to represent infinity. is it possible to assign this number using a numeric literal to a variable?
As far as I'm aware, Mathf.Infinity simply doesn't have a "normal" numerical equivalent, so no - it's not possible to assign it using a numeric literal.
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 float.MaxValue in an operation, however you can't subsequently subtract from this value to return to normal numeric values.
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.
Mathf.Infinity takes its value directly from float.PositiveInfinity which can be looked up in the MSDN reference.
PositiveInfinity is one of three "special values" that can be assigned to a float variable, in addition to the normal numeric range of values.
answered Apr 18 '10 at 04:11 PM
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 :)
answered Apr 19 '10 at 11:08 AM
visual c# says: 3.402823 * Mathf.Pow(10, 38)
unity regards this as inifinity: 3.402823 * Mathf.Pow(10, 39)
tried adding and subtracting ones from both but i couldn't get to infinity nor could i get away from it
(3.402823 * Mathf.Pow(10, 39)) - (3.402823 * Mathf.Pow(10, 38))
so i assume you could use this number: 3.402823 * Mathf.Pow(10, 38)
answered Apr 18 '10 at 02:36 PM