Advertisement

modulo proviso

Started by November 10, 2000 03:39 PM
1 comment, last by Mastiff 24 years, 1 month ago
  
double heading;
//...

if ((heading % 90) == 0)
//...

  
Why won''t this work? (The compiler gives me an illegal operand error.)
The % operator doesn''t work with doubles. You have to use fmod() instead.

if (0 == fmod(heading,90))


Regards,JumpsterSemper Fi
Advertisement
Also, it is highly, and I mean highly, unlikely that heading will ever be a perfect multiple of 90.

  double heading;heading = 90.0;heading *= 5.0;heading /= 5.0;if(heading==90.0)	{	//this will probably never be called	//maybe it will with a high precision +pentiumII..	//maybe not...	//never on a 486...	}else	{	//you''ll end up here due to rounding error	//the lsb of the floating types cannot be relied upon	}  
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara

This topic is closed to new replies.

Advertisement