Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

double

Status
Not open for further replies.
Oct 29, 2004
6
AU
is there any difference between
double (i*j)
(double) i*j


thanks for ur time
 
Without declarations and values for i and j, no.


--
 
double (i*j)" multiplies i by j, then converts the result into a double.

"(double) i*j" converts i into a double, then multiplies by j.
 
And actually, "double (i*j)" should be "(double) (i*j)" otherwise it is a syntax error.
 
teriviret,
double(i*j) is OK cast in C++...

Let's try:
Code:
#include <limits>
#include <iostream>
...
const int maxint = numeric_limits<int>::max();
...
double bad = double(i*j);// integer overflow!..
double ok = (double)i*j; // same as ((double)i)*j...
cout << bad << " " << ok << endl;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top