On Mon, 2004-08-30 at 21:17, Ed Hill wrote:
On Mon, 2004-08-30 at 21:04, Robert L Cochran wrote:
> > Does this compile for you
> >
> > #include <iostream>
> > #include <cmath>
> >
> > using namespace std;
> >
> > int main()
> > {
> > cout << "sine 63 = " << sin(63) << endl;
> > cout << "log to the base 10 of 54 = " << log10(54)
<< endl;
> > double quick = (sin(53) * sqrt(14.3443) + tanh(22)) / log(61.444);
> > cout << "quick = " << quick << endl;
> > }
Yes, explicitly converting those constants to doubles is a good idea:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
cout << "sine 63 = " << sin(double(63)) << endl;
cout << "log to the base 10 of 54 = " << log10(double(54))
<< endl;
double quick = (sin(double(53)) * sqrt(double(14.3443))
+ tanh(double(22))) / log(double(61.444));
cout << "quick = " << quick << endl;
}
which then compiles cleanly on my FC2 install (gcc 3.3.3).
[rlc@bobcp4 cpp]$ emacs tsine2.cpp
[rlc@bobcp4 cpp]$ g++ -Wall -pedantic -o tsine tsine2.cpp
[rlc@bobcp4 cpp]$ ls -al
total 24
drwxrwxr-x 2 rlc rlc 4096 Aug 30 21:19 .
drwxrwxr-x 6 rlc rlc 4096 Aug 30 20:58 ..
-rwxrwxr-x 1 rlc rlc 7739 Aug 30 21:19 tsine
-rw-rw-r-- 1 rlc rlc 342 Aug 30 21:19 tsine2.cpp
[rlc@bobcp4 cpp]$ ./tsine
sine 63 = 0.167356
log to the base 10 of 54 = 1.73239
quick = 0.606956
:-)