problem with data types in square root algorithm

if a function returns a value in long,the value is stored in double long,and given to a function which takes double,does the value change?
Assuming no data is lost when converting the value returned from the function returning a long to a long, no, there will be no change. You can even try it:
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>

int main(int argc, char *argv[])
{
	long x = 15;
	long double y = x;
	double z = y;

	std::cout << y << std::endl;
	return 0;
}
This is platform/compiler dependent.
If long is 32 bits there is no problem.

If you're on a system where long is 64 bits, double may not have enough precision to hold all values representable by a long exactly.
Last edited on
Topic archived. No new replies allowed.