Like Tree1Likes
  • 1 Post By laserlight

Why can't 'float' variables be assigned to signed or unsigned?

This is a discussion on Why can't 'float' variables be assigned to signed or unsigned? within the C++ Programming forums, part of the General Programming Boards category; I know the data types 'char','short','long', and 'int' can be signed or unsigned... but why can't 'float'? I don't see ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    67

    Why can't 'float' variables be assigned to signed or unsigned?

    I know the data types 'char','short','long', and 'int' can be signed or unsigned... but why can't 'float'? I don't see why not? But when I experiment with it on the compilier, an error occurs

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,593
    Quote Originally Posted by cplusplusnoob
    but why can't 'float'? I don't see why not?
    Probably because the built-in types were specified with known systems of representation in mind, and the relevant floating point systems don't fit the notion of an unsigned float (or unsigned double).
    cplusplusnoob likes this.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    So the question becomes why didn't the IEEE 754 standard include unsigned floating-point types. Possibly to simplify the hardware implementation. Assuming for an unsigned type that the sign bit would be allocated to the mantissa, the hardware (circa 1985) would have to deal with two sizes of mantissa. We can also assume that programmers have not been demanding an unsigned float (and one extra bit of precision) since no update has incorporated unsigned floats.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Signed and unsigned
    By ncode in forum C Programming
    Replies: 3
    Last Post: 09-02-2011, 08:59 PM
  2. Replies: 3
    Last Post: 04-18-2011, 09:15 AM
  3. Unsigned vs. Signed?
    By Programmer_P in forum C++ Programming
    Replies: 4
    Last Post: 12-22-2009, 12:15 PM
  4. Signed vs Unsigned int
    By osyrez in forum C++ Programming
    Replies: 18
    Last Post: 08-17-2006, 07:38 AM
  5. signed/ unsigned what!!
    By the bassinvader in forum C Programming
    Replies: 3
    Last Post: 07-27-2006, 01:46 PM

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