# Calculation of Infinity

**URL:** <https://forum.kirupa.com/t/calculation-of-infinity/10292>\
**Category:** flash\
**Created:** [December 28, 2002, 8:54pm UTC](https://forum.kirupa.com/t/calculation-of-infinity/10292 "2002-12-28T20:54:28Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrthad](https://avatars.discourse-cdn.com/v4/letter/a/e480ec/32.png) [@andrthad](https://forum.kirupa.com/u/andrthad)\
**Post date:** [December 28, 2002, 8:54pm UTC](https://forum.kirupa.com/t/calculation-of-infinity/10292/1 "2002-12-28T20:54:28Z")

</div>

Hi,

I have a actionscript calculation that initially calculates a value of infinity. Is there a “if” statement you can perform until the calculation actually calculates a real number (0-100)?

I can be more specific if needed.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 28, 2002, 8:57pm UTC](https://forum.kirupa.com/t/calculation-of-infinity/10292/2 "2002-12-28T20:57:53Z")

</div>

Well infinity goes on forever, so how can you calculate a value for it? That is like saying that you counted to the end of infinity :-\

What is the code you are using?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 28, 2002, 11:21pm UTC](https://forum.kirupa.com/t/calculation-of-infinity/10292/3 "2002-12-28T23:21:54Z")

</div>

yeah sounds odd, what are you doing?

There’s  
isFinite(someNumber)  
which checks to see if a number is, well finite (not infinite) as well as the constants  
Number.POSITIVE\_INFINITY  
and  
Number.NEGATIVE\_INFINITY

if that helps any

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 29, 2002, 7:39am UTC](https://forum.kirupa.com/t/calculation-of-infinity/10292/4 "2002-12-29T07:39:06Z")

</div>

Here is my code.

```auto

JukeBoxClass.prototype.checkLoad = function() {
	var percentLoaded = (MySong._framesloaded/MySong._totalframes)*100;
	if (isNaN(percentLoaded) == false){
		progressbar._xscale = Math.round(percentLoaded);
		if (percentLoaded<100) {
			txtpercent.text = Math.round(percentLoaded)+" - streaming";
		} else {
			txtpercent.text = "loaded";
		}
	}else{
		txtpercent.text = "loading.."
	}
};

```

You can see it in action here. Scroll to the next song and for a split second it will say infinity.

[http://www.thadandrews.com/SWFJukeBox.htm](http://www.thadandrews.com/SWFJukeBox.htm)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 29, 2002, 8:06am UTC](https://forum.kirupa.com/t/calculation-of-infinity/10292/5 "2002-12-29T08:06:33Z")

</div>

hehehe… well yeah, cause the when one of the expressions you have is being evaluated its value would be infinity… i thought you were talking about an integer that is actually infinity (which actually is impossible :beam: )

```php

percentLoaded = (MySong._framesloaded/MySong._totalframes)*100;

```

i guess when MySong.\_framesloaded is zero, dividing it by MySong.\_totalframes is infinity…

:A+: ![](http://www.flashdevils.com/~ahmed/hmed.gif)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 29, 2002, 8:37am UTC](https://forum.kirupa.com/t/calculation-of-infinity/10292/6 "2002-12-29T08:37:46Z")

</div>

Yeah I had a math teahcer that once talked about this. He said that if you take any number, for example 1, and divide it by zero, then it equals infinity.

This is because if you have something and divide it by 0 oarts, then you have everything, because nothing is divided. It’s kinda trippy, but I thought I’d share.

-brad-:evil:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 29, 2002, 8:42am UTC](https://forum.kirupa.com/t/calculation-of-infinity/10292/7 "2002-12-29T08:42:53Z")

</div>

oops… i got it the other way around… as leet said, when you divide a number by 0 the result is infinity, and, therefore, before the sound track is yet selected, the value of MySong.\_totalframes would be 0 and therefore giving an infinity…

:A+: ![](http://www.flashdevils.com/~ahmed/hmed.gif)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 29, 2002, 12:53pm UTC](https://forum.kirupa.com/t/calculation-of-infinity/10292/8 "2002-12-29T12:53:10Z")

</div>

> txtpercent.text = Math.round(percentLoaded)+" - streaming";

Just replace that line with:

```php
txtpercent.text = isFinite(percentLoaded) ? Math.round(percentLoaded) + " - streaming" : "0 - streaming";

```

-Al

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 29, 2002, 6:21pm UTC](https://forum.kirupa.com/t/calculation-of-infinity/10292/9 "2002-12-29T18:21:03Z")

</div>

alethos,

Thanks. Your code worked perfect. Would you explain the code. I don’t really understand the “:” or “?” syntax.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 29, 2002, 6:29pm UTC](https://forum.kirupa.com/t/calculation-of-infinity/10292/10 "2002-12-29T18:29:29Z")

</div>

? : is an if/then conditional statement. Its in Flash help under operators if you want to look it up there

basically it evaluates the first statement and depending on whether or not it is true returns ether the statment after the ? (when true) or the : (when false).

example:

value = (true) ? 1 : 2;  
trace(value); // traces 1

value = (false) ? 1 : 2;  
trace(value); // traces 2

you can compound these within one another as well

value = (a \> b) ? 1 : (a \> c) ? 2 : 3;

basically its an if/else all in one line returning the result of the evaluated line

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 29, 2002, 6:37pm UTC](https://forum.kirupa.com/t/calculation-of-infinity/10292/11 "2002-12-29T18:37:51Z")

</div>

Hey, glad it worked.

The ?: conditional is just a condensed IF statement really.

Instead of something like this:

```php
if(myWallColour == "green"){
  myOpinion = "pretty";
} else {
  myOpinion = "ugly";
}

```

you could use this:

```php
myOpinion = (myWallColour == "green") ? "pretty" : "ugly";

```

You don’t have to set the output of the ?: conditional to a variable, but that’s how I mostly use it. You could also put executable code after the ? and the :, but IF statements are a lot more readable if you want to execute anything.

In general, if “conditionalStatement” is true, then “ifTrue” is returned, else “ifFalse” is returned:

```php
conditionalStatement ? ifTrue : ifFalse

```

Hope that cleared things up a bit (sorry, I’m not great at explaining things 🙂 ).

-Al  
:: **EDIT** :: Senocular beat me to the punch. With a much better explanation. 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 29, 2002, 6:48pm UTC](https://forum.kirupa.com/t/calculation-of-infinity/10292/12 "2002-12-29T18:48:04Z")

</div>

nah yours is good, you wrote out the if else statements 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 29, 2002, 8:14pm UTC](https://forum.kirupa.com/t/calculation-of-infinity/10292/13 "2002-12-29T20:14:03Z")

</div>

Thanks to the both of you. I always say two explanations are better than one. :rambo:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 30, 2002, 12:39am UTC](https://forum.kirupa.com/t/calculation-of-infinity/10292/14 "2002-12-30T00:39:55Z")

</div>

you could always do an infinite loop  
i think its  
if(i=1; i=0; i++)  
{  
}  
am i off topic  
lol im dumb

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 30, 2002, 12:42am UTC](https://forum.kirupa.com/t/calculation-of-infinity/10292/15 "2002-12-30T00:42:26Z")

</div>

while(true){}

🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 30, 2002, 2:56am UTC](https://forum.kirupa.com/t/calculation-of-infinity/10292/16 "2002-12-30T02:56:31Z")

</div>

Hey kaotic, I believe you were going for a for loop there, not an if statement :-\

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 30, 2002, 3:08am UTC](https://forum.kirupa.com/t/calculation-of-infinity/10292/17 "2002-12-30T03:08:13Z")

</div>

i know  
lol i had a brain fart  
so many if/then/else/while commands i always get them mixed up im still a n00b man:smirk:

so then its

```php
for(i=1; i=0; i++){
}

```
