Thread: unsigned double?

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    11

    Question unsigned double?

    i wrote a program that gets the product of 5 bytes and stores it
    into a long double however when the number gets large it stores
    a negative number which corrupts my data. Is there a way i can cast it unsigned? or do i have to convert it to possitive myself by performing 2's complement or something? Don't know how to do that either using c++...
    please help me :P

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    There's no such thing as an unsigned double. However I don't know how you're managing to overflow a double with the product of 5 bytes. Are you sure it's not producing a small number with a negative exponent rather than a negative number?
    zen

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    11
    i'm not sure. what i have is 5 unsigned chars which are read from a file. then (c1*c2*c3*c4*c5) is stored in the long double sum.
    then if sum>max; max=sum; (both are same type)

    ok what is weird is if i declare them both unsigned long ints then the max is greater then when i declare them long double??

    and when i declare them unsigned long there is no negative sums however max is not what its suppose to be because its larger then unsigned long int. anyone know what kind of paradox is occuring here if its not overflowing :P
    ...

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    You need to cast your variables to long doubles.

    sum = (long double) c1 * (long double) c2 * (long double) c3 * (long double) c4 * (long double) c5;

    or maybe just casting the first is good enough:

    sum = (long double) c1 * c2 * c3 * c4 * c5;

    I think you can use the <static cast> method, but I'm not sure of the syntax.
    Last edited by swoopy; 11-20-2001 at 03:51 PM.

  5. #5
    Registered User
    Join Date
    Nov 2001
    Posts
    11
    cool it worked thanks =)
    ...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Replies: 12
    Last Post: 08-11-2008, 11:02 PM
  3. Copying 2-d arrays
    By Holtzy in forum C++ Programming
    Replies: 11
    Last Post: 03-14-2008, 03:44 PM
  4. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  5. Replies: 16
    Last Post: 10-29-2006, 05:04 AM