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

  1. #1
    Registered User
    Join Date
    Nov 2011

    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
    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).
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    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, 01: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