I'm still develloping my calculator
But, there is another problem:
sin(number1);
tan(number1);
do not give the same output as my other calculator (The one which I take to school)!
No error, and I included math.h.
What am I doing wrong?
This is a discussion on tan() and sin() within the C++ Programming forums, part of the General Programming Boards category; I'm still develloping my calculator But, there is another problem: sin(number1); tan(number1); do not give the same output as my ...
I'm still develloping my calculator
But, there is another problem:
sin(number1);
tan(number1);
do not give the same output as my other calculator (The one which I take to school)!
No error, and I included math.h.
What am I doing wrong?
Feeding degrees where radians are expected?
Show an example of expected input and output.
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
math.h functions take parameters measured in radians, not degrees.
There are 2*PI radians in a full circle, scale your angles appropriately.
sin(1); in computer: 0.841471
sin(1); in school calculator: 0.017452406
Like the others have said, you're mixing radians and degrees. Both of those are correct.Originally Posted by Ideswa
sin(1 degree) = .0174524
sin(1 radian) = .8414709
Radians and degrees are sort of like feet and meters. Just different way of measuring, for the most part. 2 * pi radians = 360 deg, as Salem said, so: pi radians = 180 degrees, pi / 2 radians = 90 deg, etc. Google it. See MathWorld's article on it, or perhaps the Wikipedia entry.
long time; /* know C? */
Unprecedented performance: Nothing ever ran this slow before.
Any sufficiently advanced bug is indistinguishable from a feature.
Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
The best way to accelerate an IBM is at 9.8 m/s/s.
recursion (re - cur' - zhun) n. 1. (see recursion)
Thanks!
this is my solution:
tangens = tan(number1);
answer = (2 * M_PI) * tangens;
aswer /= 360;
answer /= tangens;
http://www.functionx.com/bcb/math/PI.htm says:
"....Borland had included its value in the math.h library as M_PI 3.14159265358979323846."
But when I
cout << M_PI;
the output is:
3.14159
And because of that there is still a little difference between the answers:
0.017455064 (in school calc.)
0.0174533 (in my calc.)
Can I change that configuration or is that impossible with a Borland compiler?
cout will use formatting rules for output which concatenate the number.
The Windows calculator will give you .017452406
Which just goes to show that you shouldn't trust default math libraries for extreme precision.
I'm pretty sure your school calculator's answer of 0.017455064 is off the mark, because I have two calculators that give 1.7452406437, which agrees with the Windows calc. Your calculator's "answer" of 0.0174533 is an approximation of pi/180.
And it looks like that's what you're doing, too.
What is this supposed to do? This is equivalent toCode:answer = (2 * M_PI) * tangens; aswer /= 360; answer /= tangens;
which means that you're merely finding a convoluted way of assigning pi/180 to answer.Code:answer = (2 * M_PI) * tangens / 360 / tangens
This is completely wrong (as has been said).Originally Posted by Ideswa
The reason it almost works is that
tan(1 degree) = tan( pi/180 radians) ~= pi/180.
For small angles (in radians), tan(x)~=sin(x)~=x. This approximation is often used in mechanics.
EDIT: Approximations of tan(1 degree):
Windows calc: 0.017455064928217585765128895219728
MATLAB: 0.01745506492822
Last edited by Sang-drax; 02-04-2006 at 10:37 AM.
You can #undef PI * and then redefine PI:Can I change that configuration or is that impossible with a Borland compiler?
* You may not have to #undef PI, but I would put it in anyway.Code:#undef PI #define PI 3.1415926535897932384626433832795028841971693993751\ 05820974944592307816406286208998628034825342117067\ 98214808651328230664709384460955058223172535940812\ 84811174502841027019385211055596446229489549303819\ 64428810975665933446128475648233786783165271201909\ 14564856692346034861045432664821339360726024914127\ 37245870066063155881748815209209628292540917153643\ 67892590360011330530548820466521384146951941511609\ 43305727036575959195309218611738193261179310511854\ 80744623799627495673518857527248912279381830119491\
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
dwks, but the double can hold only so much.
so even if you gave one million digits the resultant number would be rounded?
That's a complete waste of time. M_PI is already defined with as many digits as can be stored in a double, so you're longer digit sequence is not going to add anything at all. Besides, theres probably more inaccuracy in the sin function, than in your digit sequence above.Originally Posted by dwks
Just use this:
inline double sin_degrees(double x)
{
return sin(x * (M_PI / 180.0));
}
Technically, M_PI is non-portable. While it's true several compilers (or their libraries) support it, there is no requirement in the C++ standard that it be supported.