17

I have personally always been of the opinion that it would make sense for the default integer type to be unsigned, though it's been a long time since that would've been a live issue for debate; C in the 1970s was already defaulting to signed integers, nor was it the first language to do so.

I'm interested in exactly when, why and how the decision was first made. In assembly language, there isn't really a default; you always specify signed versus unsigned. So we should look at high-level languages (using here the classical definition of high-level as 'higher level than assembly'). The first significantly influential high-level language was Fortran. Modern Fortran standards mandate that compilers shall treat integer variables as signed unless otherwise specified.

When did Fortran decide this? Was the decision already made in the earliest Fortran compilers? Did any compilers on any machines, treat integers as unsigned?

  • 2
    I don't think there was any "deciding" to be done - they had a target computer. – another-dave Aug 24 at 11:35
  • 18
    Re, "In assembly language, ...you always specify signed versus unsigned." I don't know what assembler you've been using, but I've never used one that allowed one to declare variables with types. All the assemblers that I've ever used allowed one to reserve space and, to use any available op-code to access that space and operate on its content. Also note: With 2s complement arithmetic, many operations (including addition and subtraction) don't come in "signed" or "unsigned" variants. That's why 2s complement: It doesn't need as many op-codes to support both signed and unsigned numbers. – Solomon Slow Aug 24 at 11:36
  • 5
    True enough, but if you've got the typical condition codes, you do need to make a choice between (for example) "branch on greater, signed" and "branch on greater, unsigned". The "specification" is therefore in terms of opcode selection - though as you say, it's not "always specify", more like "sometimes" or even "occasionally". – another-dave Aug 24 at 14:02
  • 3
    Uh, voltage is signed. Consider AC for example: swings + and - relative to a reference 0. Time is signed: when some of you were born, my age was negative :-) – another-dave Aug 24 at 23:57
  • 4
    Many of the replies implicitly assume that the designers of FORTRAN in the mid-1950s were working on an ISA like the two’s-complement machines we have today, They were not. The target architecture had a signed fixed-point type and a signed floating-point type, so that was what the original FORTRAN supported. Unsigned integer math was never an option, given their design goals. It was as simple as that. – Davislor Aug 25 at 9:30
21

FORTRAN was originally developed for the IBM 704 computer, which stored integers in sign-and-magnitude format. In the original documentation, it supports fixed-point variables, which used the machine’s native format, floating-point variables, and unsigned fixed-point constants, which were intended for line numbers and subscripts. These would be translated into offsets that fit into the 704’s index registers. Other than indexing by those three registers, the 704 had only a small handful of instruction for unsigned integer arithmetic, ACY and CAL (which could add a logical word to the accumulator). It was also possible to do multiplication by constants through a combination of shifts and additions, which was enough to compute the address of an array element, but not to perform other arithmetic.

John Backus wrote later, “We certainly had no idea that languages almost identical to the one we were working on would be used for more than one IBM computer, not to mention those of other manufacturers.”

There was no serious consideration of unsigned integer variables, because the architecture FORTRAN was designed to run on had no such native type. The decision was made for that technical reason. Considerations about how useful one would or would not have been for computational physics were not historically important to it.

| improve this answer | |
  • 9
    "Formula Translation" indicates that the language was intended for calculating things. That in itself argues in favour of being able to handle negative integers. – another-dave Aug 24 at 14:06
  • 2
    @another-dave Backus was very explicit, in his retrospective, that compiling to efficient code was a more important goal than mathematical elegance. – Davislor Aug 24 at 16:25
  • 1
    Perhaps - but I don't class negative numbers as being particularly elegant mathematics. – another-dave Aug 24 at 23:59
  • 3
    @another-dave The 704 wasn't designed for elegant mathematics, but for practical scientific and engineering calculation. And Fortran was designed to make it practical for scientists and engineers who were not specialists in machine language to program the 704. – John Doty Aug 25 at 0:22
  • 1
    @Flydog57 It didn’t historically matter to their decision, because they were writing for an ISA that did not support multiplying, dividing or subtracting unsigned fixed-point numbers. So it would not have been feasible and there is no evidence they ever considered it. – Davislor Aug 25 at 8:58
3

Fortran was developed with scientific computing in mind. Negative values clearly occur quite frequently when doing scientific computing or, for that matter, in many other problem domains that the developers of the language might have considered.

Supporting unsigned integral would have had some value but the language would have still had to support signed integral types. Since almost all interesting unsigned values fit comfortably within a signed integer variable, they may have felt that they were able to support their target audience (scientific computing) while also providing a reasonable level of support for those who really did want to work with unsigned values. Alternatively, they may have simply decided to focus on signed arithmetic without making any real effort to consider what it might mean to support unsigned arithmetic simply because their target audience would almost all need a language that supported signed values.

| improve this answer | |
  • 3
    According to the lead designer, John Backus, they didn’t think much about that when they did the language design. – Davislor Aug 25 at 4:27
  • 1
    My impression is that negative numbers tend to occur much more frequently on my bank account than "when doing scientific computing" - But your mileage may vary. – tofro Aug 25 at 7:57
  • 2
    Negative real values occur all the time in scientific computing. For integer variables, it's much more common to know the range a priori, and it either being nonnegative naturally (array indices) or at least could easily be shifted into the positive by a constant offset. But yeah, from Fortran's POV there just wouldn't have been any good reason to not allow negative integers everywhere anyway. – leftaroundabout Aug 25 at 10:19
  • 1
    @ZOMVID-20 no, unsigned ints and 2-digit years are completely different pairs of shoes. There are lots of situations where negative numbers really conceptually can/should not happen, and having a dedicated type for those is theoretically speaking good for safety. Now, you may argue that unsigned ints with their overflow behaviour do a bad job at enforcing this type guarantee, but that's more about the implementation rather than idea of unsigned types. — For 2-digit years meanwhile, it was always clear that this is never conceptually right, but just a “YAGNI” compromise. – leftaroundabout Aug 25 at 21:51
  • 1
    Unsigned integers exactly model how most computer addresses are considered: in a 16-bit address, the address after 32767 is generally thought of as address 32768, not -32768; the top of the address space is thought of as 65535, not -1. Unsigned integer arithmetic is vital to system programmers. – another-dave Aug 25 at 23:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.