HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

double function and double variable

08-05-2006, 06:31 AM#1
Linera
How exactly does a double function work?
How does a double variable work?

here is an example:
Code:
double getMobXP(int playerlvl, int moblvl)
{
	if(moblvl >= playerlvl) {
		double temp = ((playerlvl * 5) + 45) * (1 + (0.05 * (moblvl - playerlvl)));
		double tempcap = ((playerlvl * 5) + 45) * 1.2;
		if(temp > tempcap) {
			return floor(tempcap);
		}
		else {
			return floor(temp);
		}
	}
	else {
		if(getConColor(playerlvl, moblvl) == 0) {
			return 0;
		}
		else {
			return floor((playerlvl * 5) + 45) * (1 - (playerlvl -  moblvl)/getZD(playerlvl));
		}
	}
}
08-05-2006, 09:20 AM#2
Jacek
Erm... double is like float but more precise
08-05-2006, 10:27 AM#3
Linera
What is a float?


p.s. I don't know c++
08-05-2006, 10:29 AM#4
Mezzer
A double is a (potentially) longer real number, and you use it as such
08-05-2006, 10:34 AM#5
Linera
I would like to know how it works
08-05-2006, 10:37 AM#6
PitzerMike
It works like an int just that it's a float point number:

Code:
double d = 0.99;
return d;
08-05-2006, 12:37 PM#7
Vexorian
doubles take 8 bytes in 32 bits architectures, and floats 4 . So doubles are more precise and have less limits
08-05-2006, 06:07 PM#8
Linera
ummmm, I'm still confused.
08-05-2006, 06:30 PM#9
Alevice
It's just like a real variable. By precision, understand it as it lets you have much more decimals. Don't worry much about it.
08-05-2006, 11:32 PM#10
PipeDream
It's a number written in hardware in scientific notation. Take 5.3*10^2. There's a mantissa (5.3) and an exponent (2) and a sign (+). This abstracts the precision (bits you give to the mantissa) from the range (bits you give to the exponent). For a double, you get around 15 digits of precision and a range up to 10^300ish. For floats, you get around 7 digits of precision and a range up to 10^40ish.

Floating point arithmetic is tricky to get right. It has many non intuitive limitations. Google around for tutorials.

Search for IEEE 754 if you're curious about how it works on a bit level.
08-05-2006, 11:34 PM#11
Chrono Trigger
Where can i find free 3DSMAX 4?
08-06-2006, 12:21 AM#12
Linera
Quote:
Originally Posted by Chrono Trigger
Where can i find free 3DSMAX 4?
1st off, Wrong forum.

2nd off, Wrong topic.
08-06-2006, 01:04 AM#13
Tim.
Quote:
Originally Posted by Chrono Trigger
Where can i find free 3DSMAX 4?
Read our Rules and don't go offtopic.