[gcompris-devel] Divide by zero in clockgame.c...

Herman Bruyninckx Herman.Bruyninckx at mech.kuleuven.ac.be
Tue Oct 23 15:39:06 UTC 2001


I've been looking some more into the problems I have with
clockgame.c... and found the solution.

The problem is that the original line 628:

  angle = M_PI/2 - atan(new_y/new_x) + ((new_x<0) ? M_PI : 0.0);

gives an error when new_x == 0. This, I could prove very easy by
testing: every time that I grab the hour or minute angle and pass
through the vertical center line, I got the error. (So, I am very
surprised that you guys don't have this error... It took me a long
time to become aware of the fact that just recompiling didn't change
anything, because the installed shared libraries were always kept
unchanged, unless I did a full `make install').

I solved it as follows:

  angle =  atan2(new_x,new_y);
  if (angle<0) {angle= angle + 2.0*M_PI;}

The atan2 finds the angle (between -pi and +pi); in order to have an
angle between 0 and 2 pi, I have to wrap negative angles.

This solution works fine for me.

Best regards,

Herman






More information about the Gcompris-devel mailing list