C++ sin() returns incorrect results -
i have piece of code
bool position::hasinline(const unit * const target, float distance, float width) const { if (!hasinarc(m_pi, target) || !target->iswithindist3d(m_positionx, m_positiony, m_positionz, distance)) return false; width += target->getobjectsize(); float angle = getrelativeangle(target); float abssin = abs(sin(angle)); return abs(sin(angle)) * getexactdist2d(target->getpositionx(), target->getpositiony()) < width; }
problem ran is, when debug gdb , try "p sin(angle)" returns weird values - angle 1.51423 states sin = 29 (so yes, putting in radians :-) ). more weird is, when try "p abssin" returns 0, , yes, on next line, "float abssin = abs(sin(angle))" line done. originaly there wasnt included cmath, m_pi const returning correct value, though added #include @ start of .cpp file make sure, nothing changed.
if helps, im using linux kernel 2.6.26-2-xen-amd64 ideas?
the function abs
(as defined in cstdlib
) takes integer , returns integer. when dealing double
s, should using fabs
instead.
another version of abs
defined in cmath
(#include <cmath>
). overloaded accept (and return) both integers , doubles.
you may wish double-check version using.
Comments
Post a Comment