This is how Blender handles quaternion rotation (which is not how I would prefer Blender handled it.) It uses the sign of the W channel to indicate the direction of rotation (mostly, because it doesn’t slerp.) This means that you can have a rotation of 360 degrees or -360 degrees, and it it goes from one to the other, well, it interpolates between those two rotations.
What you can do is have a keyframe at frame 39.5 and at frame 40, so the interpolation happens between frames. But no, that’s not really ideal.
You can also use Eulers, which will let you key your frame 40 to 360 degrees and your frame 80 to 720 degrees. That’s not really ideal either-- it solves motion blur and fcurve handle problems with the quaternion solution I mentioned, but it introduces problems with NLA (and maybe with fcurve modifiers.)
Eventually, the plan is for Blender to get quaternion slerp support, at which point this stops being a problem, but who knows when that will happen.