using a double in a for loop

Hi I have an issue with an, "Illegal use of floating point in function"

1
2
3
4
5
6
7
8
for (double i = 0; i < numTerms; i++)
	{
		if (term == Terms[i])
		{
			return true;
		}
	}
	return false;


Anyone know how I can implement this? the error comes when I use the floating point 'i' inside Terms[i].. I am basically trying to handle a very large number of terms..
Last edited on
double means i can take the value of say 0.5 or whatever and then later how can you use that as an index to reference Terms array ?

e.g
Terms[0.5] will be an error.

Try to use long datatype to see if it satisfy besides the traditional int datatype if you have a large number of terms.
hi sohguanh,

that makes perfect sense, and I was thinking the same thing, I just didn't know how to get past that..

I just looked up what the max value a long and int can both have, and they both seem to be the same value? See below.. I thought I used unsigned, but it looks like I didn't.. I'll see if I can get away with unsigned.. Or otherwise.. I'll give 'long' a shot.. is there another value besides 'long' I can use thats even bigger? Thanks again!

INT_MIN
Minimum value for a variable of type int.
–2147483648

INT_MAX
Maximum value for a variable of type int.
2147483647

UINT_MAX
Maximum value for a variable of type unsigned int.
4294967295 (0xffffffff)

LONG_MIN
Minimum value for a variable of type long.
–2147483648

LONG_MAX
Maximum value for a variable of type long.
2147483647

ULONG_MAX
Maximum value for a variable of type unsigned long.
4294967295 (0xffffffff)
You could use the type: unsigned long long or unsigned long long int (they are practically the same).
Last edited on
is there another value besides 'long' I can use thats even bigger? yes there is (like long long or __int64 (Microsoft specific)) but don't use it as an index of a loop you don't want to loop that often
If your requirement is so unique that the number of Terms can actually "burst" the datatype limits, then I think you can no longer just use pure memory. You may need to consider the need to have text file or even database to store those data. Then read them in batches and process them in batches. Something like when items too huge to be sorted in pure memory, we use file to store intermediate results like merge sort does.

great stuff guys, you all are soldiers, thanks so much.. I think this information points me in the right direction.
Topic archived. No new replies allowed.