Thread: Rounding error when casting double to short

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    204

    Rounding error when casting double to short

    I have a mathematical problem with C. For some reason the variables x and y in the code below are not exactly equal all of the time. I believe that the problem has to do with casting. How, exactly do I cast the equations for x and y so that they are always equal?

    Code:
    long x, y, w;
    double a, b;
    
    x = a*w/b+0.5;
    Last edited by thetinman; 10-23-2006 at 06:25 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ to C Conversion
    By dicon in forum C Programming
    Replies: 7
    Last Post: 06-11-2007, 08:38 PM
  2. Conversion From C++ To C
    By dicon in forum C++ Programming
    Replies: 2
    Last Post: 06-10-2007, 02:54 PM
  3. functions and passing data
    By redmondtab in forum C Programming
    Replies: 41
    Last Post: 09-21-2006, 12:04 PM
  4. Please HELP!!
    By traz in forum C++ Programming
    Replies: 4
    Last Post: 04-14-2003, 09:20 PM
  5. Color Variety
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 10-23-2002, 09:17 AM