Unknown Math Function

This is a discussion on Unknown Math Function within the C Programming forums, part of the General Programming Boards category; Hey, Alright, right now, I'm having trouble figuring out how to do a little math problem with doubles. I need ...

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    28

    Unknown Math Function

    Hey,

    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?



    Thanks!

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    Try this
    double modf(double x, double *iptr);

    DESCRIPTION
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 04:45 PM
  2. Math Function Input
    By swanley007 in forum C++ Programming
    Replies: 2
    Last Post: 02-15-2006, 06:29 PM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01: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, 09:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21