Thread: % and floats

  1. #1
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002

    % and floats

    I never knew there was a problem with using % with floats. However, I just got this error:
    error C2296: '%' : illegal, left operand has type 'float'
    I'd like to constrain the float variable to values between 0 and 2PI (radian measurements, and I'd prefer not to lose precision as the value continues to increase) Is there a way to do it without using while loops - a modulus for floats? I could code it easily enough like that, but it seems ugly and slow.


  2. #2
    Disturbed Boy gustavosserra's Avatar
    Join Date
    Apr 2003
    I donīt think so.
    And I think that is impossible to have a "mod" to float because float division does not have rest.
    Nothing more to tell about me...
    Happy day =)

  3. #3
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    There's the fmod function. That'll do what you're asking with out any unneeded performance hit.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. variables larger than floats
    By a.mlw.walker in forum C Programming
    Replies: 13
    Last Post: 04-23-2009, 02:28 AM
  2. Reading errors in floats
    By Improvolone in forum C++ Programming
    Replies: 8
    Last Post: 03-21-2006, 02:20 PM
  3. comparing two arrays of floats
    By COBOL2C++ in forum C++ Programming
    Replies: 7
    Last Post: 07-16-2003, 03:22 AM
  4. rewritten scanf for floats
    By monkey_C in forum C Programming
    Replies: 3
    Last Post: 12-09-2002, 03:21 PM
  5. Using floats in conditional statements
    By DBB in forum C++ Programming
    Replies: 3
    Last Post: 09-12-2001, 07:54 AM
Website Security Test