Thread: Unknown Math Function

  1. #1
    Registered User
    Join Date
    Jan 2005

    Unknown Math Function


    Alright, right now, I'm having trouble figuring out how to do a little math problem with doubles.

    I need to divide two real numbers, and take the fractional remainder of the two numbers (without the integer), and proceed to manipulate that... (Using variables)

    So, for example, if I were to evaluate the simple expression:

    268 / 6.82

    It would yield an answer of: 39.296187683284

    I need to take the .296187683284, and manipulate that, but I will need to later print the 39.
    Of course, I thought to evaluate the 268 / 6.82 as both an int and a double, and then subtract them from one another, but as you know, the int would round up if it were .5 and above. Sure, I've tried using the % function, but, as you know, it only works when both operands are ints.

    Anyone have any ideas?
    Is there some sort of other function I could use?


  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Try this
    double modf(double x, double *iptr);

    The modf() function breaks the argument x into an integral part and a
    fractional part, each of which has the same sign as x. The integral
    part is stored in iptr.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  2. Math Function Input
    By swanley007 in forum C++ Programming
    Replies: 2
    Last Post: 02-15-2006, 07:29 PM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM