Math.h not working properly? -


i'm having strange problem has been driving me crazy while. part of code requires c++ calculate simple arithmetic using math.h, spitting out incorrect values! here section of code:

for(int = 0; < data.size(); i++)  {  cout << (data[i][8]/dp)/2 << " : " << -log(tan(acos(data[i][8]/dp)/2)) << endl;  } 

which gives following output:

0.5 : inf 0.5 : inf -0.5 : -37.3319 0.5 : inf -0.5 : -37.3319 0.5 : inf 0.5 : inf -0.5 : -37.3319 -0.5 : -37.3319 -0.5 : -37.3319 0.5 : inf -0.5 : -37.3319 -0.5 : -37.3319 0.5 : inf 0.5 : inf -0.5 : -37.3319 -0.5 : -37.3319 0.5 : inf 0.5 : inf 0.5 : inf 0.5 : inf -0.5 : -37.3319 -0.5 : -37.3319 -0.5 : -37.3319 -0.5 : -37.3319 0.5 : inf -0.5 : -37.3319 0.5 : inf -0.5 : -37.3319 -0.5 : -37.3319 -0.5 : -37.3319 0.5 : inf -0.5 : -37.3319 0.5 : inf -0.5 : -37.3319 -0.5 : -37.3319 -0.5 : -37.3319 0.5 : inf -0.5 : -37.3319 -0.5 : -37.3319 0.5 : inf 0.5 : inf -0.5 : -37.3319 0.5 : inf 0.5 : inf 

which of course, wrong, plugging 0.5 or -0.5 -ln(tan(arcos())) on calculator gives -0.54 , -.54+3.14i, while math.h somehow returning inf , -37. have insight on how happening? in advance!

i think have missing parentheses. in output line, first value (data[i][8]/dp)/2, that's not you're using in function call (spaces added clarity):

 -log( tan( acos( data[i][8]/dp ) /2) ) 

correct line should be:

cout << (data[i][8]/dp)/2 << " : " << -log(tan(acos((data[i][8]/dp)/2))) << endl; 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -