mantissa, sign, exponent

This is a discussion on mantissa, sign, exponent within the C Programming forums, part of the General Programming Boards category; yes I know it's a type I am just asking for the purpose of extracting mantissa sign and exponent why ...

  1. #16
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    yes I know it's a type I am just asking for the purpose of extracting mantissa sign and exponent why does the sign has to be the type of int_4 and the mantissa has to be int_u8, like that??

  2. #17
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,027
    They don't. It's just a matter of choosing an appropriate type big enough to hold it.
    The sign can be uint8_t, the exponent can be uint16_t and the mantissa can be uint32_t. These are the smallest possible types to hold all data. That's all.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #18
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    and does it matter in 64 bit computers there isn't any difference to hold these values because a float is a 32 bit too, but what matters is that the size of int is different in 64 bit right?? like they are 8 byte instead of 4 byte?? am I right??

  4. #19
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,027
    Quote Originally Posted by -EquinoX- View Post
    ...but what matters is that the size of int is different in 64 bit right?? like they are 8 byte instead of 4 byte?? am I right??
    Yes, in sense that they must be large enough to hold the value.
    But int is not guaranteed to be 64-bit on 64-bit machines. Int is merely 4 bytes under 64-bit Windows.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #20
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    okay so if there is an assignment that would ask you to use a typedef to assign int_4, int_u4, int_8, and int_u8 into a 64 bit machine.. how would you do this?? assuming it's running on windows

  6. #21
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,027
    If it's just a 64-bit machine and if you can use existing typedefs, then just do
    typedef int_4 int32_t
    If you can't, then do a proper sizeof of all types to see their actual size, and then typedef them.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #22
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    no I want int_4 to be the type not int32_t so I guess you have it reversed

  8. #23
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,027
    Yes, of course, my mistake.
    typedef int32_t int_4;
    ^^"
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #24
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Ya know, between the various threads -EquinoX- has created on essentially the same problem, and all of the twists and turns and arguments and explanations, I have to say: I am almost thoroughly confused as to the point of it all.

    At best I'd like to think it is about capturing the bit image of an IEEE-754 single-precision floating point value and separating those bits into 3 integral values for sign, exponent, and mantissa. Plus some caveat about trying to be portable.

    We've mentioned the usual approaches: wandering the bytes, casting, and a union. All have various portability issues.

    Is there someone, anyone, who can give me the nickel summary?
    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.*

  10. #25
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,027
    I don't really think I understand 100% either. Just about the capturing the sign, exponent and mantissa from the float and that it will (probably) be done on a 64-bit system.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #26
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Why not just print if into a string and all your problems are solved.

  12. #27
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    "print if"? I guess you mean "printf", or more precisely "sprintf", right? Printing "if" into a string would get you a string with, well, "if", which is hardly helpful.

    With that method, you won't get the exact exponent and mantissa.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  13. #28
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,027
    Why not just print it...
    I think that's closer, especially since "f" is just under "t".
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #29
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    On whose keyboard? Maybe esbo has a Dvorak keyboard . . . .

    You're probably right, though.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. floating point number comparison
    By stanlvw in forum C++ Programming
    Replies: 9
    Last Post: 04-27-2009, 02:44 PM
  2. how to convert decimal to floating point number
    By -EquinoX- in forum C Programming
    Replies: 98
    Last Post: 03-04-2008, 01:25 PM
  3. Sign ' is the same as \' ?
    By George2 in forum C Programming
    Replies: 1
    Last Post: 11-23-2007, 07:32 AM
  4. Floating-Point Numbers
    By MindLess in forum C Programming
    Replies: 4
    Last Post: 06-25-2007, 12:45 AM
  5. My own itoa()
    By maxorator in forum C++ Programming
    Replies: 18
    Last Post: 10-15-2006, 12:49 PM

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