varaible help...?

This is a discussion on varaible help...? within the C++ Programming forums, part of the General Programming Boards category; >Though I believe technically you can leave it in. Yes...if you discard everything past the decimal place. Integers and floating-point ...

  1. #16
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Though I believe technically you can leave it in.
    Yes...if you discard everything past the decimal place. Integers and floating-point are different beasts fundamentally, even though you can use floating-point types to represent integral values with a little effort.
    My best code is written with the delete key.

  2. #17
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    18 quintillion, four hundred and forty-six quadrillion,seven hundred forty-four trillion,seventy three billion,seven hundred nine million, five hundred fifty-one thousand, six hundred and fifteen


    So I can get that many numbers crambed into the int? How big would the int be if they were all filled up?

  3. #18
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    Yes, you leave out the int part.

  4. #19
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    >>The largest possible standard built-in type in C++ is long double.
    Ah. I was just about to post that "unsigned long long x;" gave me a compile error.

    Apparently, on my C++ implementation/platform/whatever, long doubles are the same as doubles. Both are 8 bytes.

    >>Though I believe technically you can leave it in.
    Well, it won't compile on MSVC so I'm assuming that you can't (since MSVC tends to allow more than it disallows).
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  5. #20
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    oh umm sorry I got this wrong. I want to use float. And float, I'm pretty sure, can handle decimal points. But I also heard they can be off when adding 2+2. I tried it and it was correct but so I could use a long double float?



    And if a byte = 2 letters or numbers (or 1 of each) how can a long be 8 bytes and hold so much. Or are you talking about 8 bytes * the int. What the heck how does that work?

  6. #21
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >So I can get that many numbers crambed into the int?
    Only if by "int" you mean "several int manhandled to work together so that they look like one int".

    >Well, it won't compile on MSVC so I'm assuming that you can't
    Whoops, I was thinking in abstract terms when the question was about type declarations. Silly me.
    My best code is written with the delete key.

  7. #22
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    >>But I also heard they can be off when adding 2+2.
    I certainly would hope that computers are smarter than that. Otherwise the world will be doomed when they take over.

    >>a long double float
    float and double are both floating-point values. double is twice the size of a float. You should realize that double is a built-in datatype just like int
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  8. #23
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    ok ok, all of these people posting at the same time is crazy but,

    Now let me see if I got this...


    double is a whole diferent type of varaible, right?

    So then can it handle + and - and decimals?

    and can I still put a long before it?

  9. #24
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    And if a byte = 2 letters or numbers (or 1 of each) how can a long be 8 bytes and hold so much. Or are you talking about 8 bytes * the int. What the heck how does that work?
    A byte is 8 bits. A bit is either 1 or 0. So with all possible bit combinations, that makes up to 256. A long has 4 bytes, therefore 4 * 8 = 32 bits -> 2^32 possible values. 8 bytes -> 8 * 8 = 64 bits -> 2^64 possible values.

    [edit]The 2 letters or numbers you're referring to is the hexadecimal representation. Hex is a base 16 number system, so you go 1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,10,11,... It actually has 256 possibilities.
    Last edited by Hunter2; 09-13-2004 at 06:52 PM.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  10. #25
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    mmmm I get it now...

    ok not really I will just live with that long number you gave before.

  11. #26
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >double is a whole diferent type of varaible, right?
    There are three floating-point types: float, double, and long double. You can think of them in similar terms as short, int, and long int, except for floating-point.

    >So then can it handle + and - and decimals?
    Yes, it's a numeric type, so naturally it supports the numeric operations.

    >and can I still put a long before it?
    Yes, but keep in mind that long double is technically a different type. C++ is picky about types matching up, and double is the default floating-point type.
    My best code is written with the delete key.

  12. #27
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    >>double is a whole diferent type of varaible, right?
    Yes.

    >>So then can it handle + and - and decimals?
    Yes.

    >>and can I still put a long before it?
    Yes. Except the additional 'long' isn't guaranteed to make it any bigger (as my quick test showed, with both double and long double being 8 bytes).
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  13. #28
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    alright so a long double + double = messed up? So basicly I have to pick 1 type before I start making my program?

  14. #29
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    >>So basicly I have to pick 1 type before I start making my program?
    Yes.
    If you're going to use built-in math functions, use double; if you're not, use long double if you're going to need all the storage you can possibly have.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  15. #30
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >A byte is 8 bits.
    Not necessarily, though octets (as they're called) are the most common by far.

    >A long has 4 bytes
    At least.

    >alright so a long double + double = messed up?
    No, because of type conversions, long double + double = long double.
    My best code is written with the delete key.

Page 2 of 3 FirstFirst 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-22-2002, 10:02 PM
  2. function return varaible
    By Kohatian 3279 in forum C++ Programming
    Replies: 1
    Last Post: 03-28-2002, 09:51 PM
  3. varaible trouble
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 03-15-2002, 07:03 AM

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