Link to home
Create AccountLog in
Avatar of julieha
julieha

asked on

How to change variable type?

I have a variable declared as double x.
If I am doing a calculation using a function,  f = exp(x), but the data range of x is from -10000 to 10000, the computation will never finish because it will be too large calculation.
how can i change variable type of x?
Avatar of favoretti
favoretti
Flag of Netherlands image

Either cast it or re-declare?
Avatar of evilrix
>> how can i change variable type of x?
I'm not quite sure how changing the type will solve this. Isn't it the data range you need to modify? Even if you change the type of x to a different type you'll still be processing the same range won't you?

Anyway, you can't change the type of x as it's set at compile time but you can cast it to generate a temporary that will be of a different type. You do this using the static_cast operator.

int main()
{
	double double_x = 0.0;
	int int_x = static_cast<int>(double_x);
	return 0;
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Infinity08
Infinity08
Flag of Belgium image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
>>>> I know of no standard type that can represent those values ;)
I don't know a printer which would print that number before the next big bang.
> I don't know a printer which would print that number before the next big bang.

Why not?  It's only 4343 digits
He probably meant counting towards it ... :)
Avatar of julieha
julieha

ASKER

well, i will try to think of fixing the function.
thanks guys
how are you using the function?