Why is there no concept of unsigned floats?

My use case may be a little simple, but why is there not an unsigned float type in any language?

It seems like positive real numbers is a useful subtype for many engineering problems?

Are unsigned ints only done for performance reasons?


edit: related to following stack overflow post

The stackoverflow post you linked is pretty good already.

Because there’s no hardware support and no standard for it.

Is it? What problems do you have in mind? What real number problems never involve negation or substraction (see below)?

There are many properties that unsigned integer format has but are not possible for a “unsigned floating point format”.

  1. The unsigned int and signed int has the same representation. Not possible with existing signed floating point type since it’s not stored as 2s complement. In fact, signed int is a special interpretation of unsigned int, not the other way around. I’m not aware of a way to make a signed floating point format that is based on an unsigned version with easy to understand semantics.

  2. Unsigned int has well defined wrapping behavior (related to 1). Not possible for floating point format. (Not any simple ways that I can come up with at least)

  3. Negation and substraction are well defined for/between any unsigned int(s). Direct consequence of 2. Not possible with floating point.

  4. Unsigned int is used to represent addresses and sizes, so computers natually need them. There isn’t a need like this for floating point.

Also note that the OP in the stkovr question isn’t really asking for a different format, he is really asking for range check, which is a somewhat useful feature to have in languages and is possible in julia with custom types. (and there was a very recent thread about it here)

3 Likes

Could you link that thread please?

2 Likes