x


what is the real value of Mathf.infinity

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?

more ▼

asked Apr 18 '10 at 01:13 PM

Ashkan_gc gravatar image

Ashkan_gc
9.1k 33 56 117

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

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.

The other values are NegativeInfinity and Not a Number (NaN) (these also do not have a real numeric value equivalent!).

more ▼

answered Apr 18 '10 at 04:11 PM

duck gravatar image

duck ♦♦
41k 92 148 415

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 MSDN

Apr 19 '10 at 10:02 AM Ashkan_gc

You see able to do this, as you suggest.

Apr 19 '10 at 11:13 AM Horsman
(comments are locked)
10|3000 characters needed characters left

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 :)

more ▼

answered Apr 19 '10 at 11:08 AM

Ashkan_gc gravatar image

Ashkan_gc
9.1k 33 56 117

(comments are locked)
10|3000 characters needed characters left

visual c# says: 3.402823 * Mathf.Pow(10, 38)
which unity too can handle as a number

unity regards this as inifinity: 3.402823 * Mathf.Pow(10, 39)
(both using javascript or c#)

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))
is still infinity

so i assume you could use this number: 3.402823 * Mathf.Pow(10, 38)

more ▼

answered Apr 18 '10 at 02:36 PM

matyicsapo gravatar image

matyicsapo
659 12 15 27

See http://en.wikipedia.org/wiki/Floating_point_number#Infinities for a reference to how floating point numbers represent infinities.

Apr 18 '10 at 04:30 PM KvanteTore
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x211
x35

asked: Apr 18 '10 at 01:13 PM

Seen: 2060 times

Last Updated: Apr 18 '10 at 01:13 PM