tan (math.h) doesn't work?!?
Or am I missing something?
This line of code...
float temp = tan(1.5);
...results in temp equal to -.69027. According to my calculations, and to every calculator's calculations, it should equal 14.something.
Does anyone know what's up with that?
I forgot to add that I just recompiled all of this code in VS2005. The same code previously worked in VS.NET 2003.
Meh. There must be some namespace pollution interfering (no, I didn't do it, and I'm very annoyed).
Thanks anyway to anyone who was scratching their heads.
Thanks anyway to anyone who was scratching their heads.
Is that the actual code causing the trouble?
Could you post the actual function you're having trouble with, and a little context code from around where you call it?
Could you post the actual function you're having trouble with, and a little context code from around where you call it?
Don't you get a warning when compiling that? VC2003 gives me a warning, since there is an implicit conversion from double to float there.
Shouldn't matter... but just for kicks, what happens if you do
float temp = tan(1.5f);
Shouldn't matter... but just for kicks, what happens if you do
float temp = tan(1.5f);
As of 1998, it's spelled <cmath>, and it lives in namespace std. Voila, no more namespace pollution, unless someone deliberately put things into namespace std or defined a macro for tan - either of which is grounds for Nasty Disciplinary Action (TM).
Quote:Original post by phil_tThat wont change anything. 1.5 is already perfectly representable as a float, so there is no loss of precision.
Don't you get a warning when compiling that? VC2003 gives me a warning, since there is an implicit conversion from double to float there.
Shouldn't matter... but just for kicks, what happens if you do
float temp = tan(1.5f);
What's more, the result of tan isn't able to be perfectly represented as a float, so you will get a conversion warning there. You should use:
float temp = tanf(1.5);
Actually
temp float = tan(1.5f);
is fine, because there is an overload of tan with a float as a parameter. That code produces no warnings.
I'm not sure where its being included from though. MSVC won't show me. It doesn't appear to be in math.h though.
edit: ah, ok, it's this line in math.h
temp float = tan(1.5f);
is fine, because there is an overload of tan with a float as a parameter. That code produces no warnings.
I'm not sure where its being included from though. MSVC won't show me. It doesn't appear to be in math.h though.
edit: ah, ok, it's this line in math.h
inline float __cdecl tan(float _X) {return (tanf(_X)); }
Quote:Original post by ZahlmanUnfortunately, we are integrating a LOT of c code from other people, and this code is theirs. Even though I probably can't make the cmath change myself, I'm going to do it experimentally and see what happens.
As of 1998, it's spelled <cmath>, and it lives in namespace std. Voila, no more namespace pollution, unless someone deliberately put things into namespace std or defined a macro for tan - either of which is grounds for Nasty Disciplinary Action (TM).
And to answer the question someone asked, this is the code I am looking at at the moment, simply a test case that I could play with...
I have traced into the tan function call, which passes through a couple of defines from the header, and eventually calls into the actual tan function, which results in temp having a value of -.69... I'm more confused now. It is clearly calling the correct function.
float temp = std::tan(1.5f);temp = std::atan(temp);temp = 0.0f;
I have traced into the tan function call, which passes through a couple of defines from the header, and eventually calls into the actual tan function, which results in temp having a value of -.69... I'm more confused now. It is clearly calling the correct function.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement