Skip to main content
deleted 21 characters in body
Source Link
Davislor
  • 1.6k
  • 10
  • 13

There was, at the time, an alternative: the same CPUs also had a negative flag, and BCPL’s truth value was -1, so B might have instead defined all negative numbers as truthy and all non-negative numbers as falsy. (There is one remnant of this approach: many system calls in UNIX, developed by the same people at the same time, defines all error codes as negative integers. Many of its system calls return one of several different negative values on failure.) So be thankful: it could have been worse!

There was, at the time, an alternative: the same CPUs also had a negative flag, and BCPL’s truth value was -1, so B might have instead defined all negative numbers as truthy and all non-negative numbers as falsy. (There is one remnant of this approach: many system calls in UNIX, developed by the same people at the same time, defines all error codes as negative integers. Many of its system calls return one of several different negative values on failure.) So be thankful: it could have been worse!

There was, at the time, an alternative: the same CPUs also had a negative flag, and BCPL’s truth value was -1, so B might have instead defined all negative numbers as truthy and all non-negative numbers as falsy. (There is one remnant of this approach: UNIX, developed by the same people at the same time, defines all error codes as negative integers. Many of its system calls return one of several different negative values on failure.) So be thankful: it could have been worse!

Reworded discussion about why ~0 != !0.
Source Link
Davislor
  • 1.6k
  • 10
  • 13

Algol, the great-granddaddy of C++, Java and C#, defined true and false in a way that came to feel intuitive to programmers: “truth values which, regarded as a binary number (true corresponding to 1 and false to 0), is the same as the intrinsic integral value”. However, one disadvantage of this is that logical and bitwise not cannot be the same operation: On any modern computer, ~0 equals -1 rather than 1 and ~1 equals -2 rather than 0. Even (Even on some sixty-year-old mainframe where ~0 represents -0 or INT_MIN, ~0 != 1 on every CPU ever made, and the C language standard has required it for many years, while most of its daughter languages don’t even allowbother to support sign-and-magnitude or one’s-complement at all.)

Algol, the great-granddaddy of C++, Java and C#, defined true and false in a way that came to feel intuitive to programmers: “truth values which, regarded as a binary number (true corresponding to 1 and false to 0), is the same as the intrinsic integral value”. However, one disadvantage of this is that logical and bitwise not cannot be the same operation: On any modern computer, ~0 equals -1 rather than 1 and ~1 equals -2 rather than 0. Even on some sixty-year-old mainframe where ~0 represents -0 or INT_MIN, ~0 != 1 on every CPU ever made, and the C language standard has required it for many years, while most of its daughter languages don’t even allow sign-and-magnitude or one’s-complement at all.

Algol, the great-granddaddy of C++, Java and C#, defined true and false in a way that came to feel intuitive to programmers: “truth values which, regarded as a binary number (true corresponding to 1 and false to 0), is the same as the intrinsic integral value”. However, one disadvantage of this is that logical and bitwise not cannot be the same operation: On any modern computer, ~0 equals -1 rather than 1 and ~1 equals -2 rather than 0. (Even on some sixty-year-old mainframe where ~0 represents -0 or INT_MIN, ~0 != 1 on every CPU ever made, and the C language standard has required it for many years, while most of its daughter languages don’t even bother to support sign-and-magnitude or one’s-complement at all.)

Reworded discussion about why ~0 != !0.
Source Link
Davislor
  • 1.6k
  • 10
  • 13

Algol, the great-granddaddy of C++, Java and C#, defined true and false in a way that came to feel intuitive to programmers: “truth values which, regarded as a binary number (true corresponding to 1 and false to 0), is the same as the intrinsic integral value”. However, one disadvantage of this is that logical and bitwise not cannot be the same operation: On any modern computer, ~0 equals -1 rather than 1 and ~1 equals -2 rather than 0. Even on some sixty-year-old mainframe where ~0 represents -0 or INT_MIN, the language standard requires that ~0 != 1 on every CPU ever made, and that !0 == 1the C language standard has required it for many years, while most of its daughter languages don’t even allow sign-and-magnitude or one’s-complement at all.

Algol, the great-granddaddy of C++, Java and C#, defined true and false in a way that came to feel intuitive to programmers: “truth values which, regarded as a binary number (true corresponding to 1 and false to 0), is the same as the intrinsic integral value”. However, one disadvantage of this is that logical and bitwise not cannot be the same operation: On any modern computer, ~0 equals -1 rather than 1 and ~1 equals -2 rather than 0. Even on some sixty-year-old mainframe where ~0 represents -0 or INT_MIN, the language standard requires that ~0 != 1 and that !0 == 1.

Algol, the great-granddaddy of C++, Java and C#, defined true and false in a way that came to feel intuitive to programmers: “truth values which, regarded as a binary number (true corresponding to 1 and false to 0), is the same as the intrinsic integral value”. However, one disadvantage of this is that logical and bitwise not cannot be the same operation: On any modern computer, ~0 equals -1 rather than 1 and ~1 equals -2 rather than 0. Even on some sixty-year-old mainframe where ~0 represents -0 or INT_MIN, ~0 != 1 on every CPU ever made, and the C language standard has required it for many years, while most of its daughter languages don’t even allow sign-and-magnitude or one’s-complement at all.

Reworded discussion about why ~0 != !0.
Source Link
Davislor
  • 1.6k
  • 10
  • 13
Loading
Added note about binary representations.
Source Link
Davislor
  • 1.6k
  • 10
  • 13
Loading
added 158 characters in body
Source Link
Davislor
  • 1.6k
  • 10
  • 13
Loading
added 24 characters in body
Source Link
Davislor
  • 1.6k
  • 10
  • 13
Loading
added 24 characters in body
Source Link
Davislor
  • 1.6k
  • 10
  • 13
Loading
Source Link
Davislor
  • 1.6k
  • 10
  • 13
Loading