4 ms·
>It says ~100ms, but I feel sure that that's a typo — ~100 is -101 Using tilde to mean "approximately" is way more common than using it to mean "bitwise-negati
by Arnavion 6y ago
>It says ~100ms, but I feel sure that that's a typo — ~100 is -101
Using tilde to mean "approximately" is way more common than using it to mean "bitwise-negation in two's complement", not in the least because the latter meaning is specific to programming and even more specific to certain programming languages.
- cogman10 6y agoNot even programming language but in fact hardware architectures. While everything now-a-days does twos compliment there were a few early architectures that did ones compliment and a few that did just signed bits (Heck, IEEE 754 floats use signed bits, not two's complement. But that's mostly because there are no advantages AFAIK to a two's complement float)
- kragen 6y agoI would be surprised to learn that there were implementations of C on sign-magnitude or one's-complement architectures that implemented "~" as anything other than bit inversion interpreted in two's-complement, and yet were sufficiently compatible that they could run large C programs developed on more traditional architectures. Are you familiar with any? C does not permit the application of "~" to floating-point numbers. JS does, but it converts them to integers first, and interprets it as bit inversion in two's-complement.
- AnimalMuppet 6y agoIf I understand correctly, ~ means raw "invert the bits". Two's complement doesn't enter into the picture - it relates to how the bits are interpreted, which is a layer above what ~ does. One's complement, two's complement, unsigned... we don't care, just invert the bits.
- kragen 6y agoYou're reasoning from a sort of Platonic perspective. But when people are writing compilers, among the tradeoffs they are facing are whether to try to make their compiler compile an existing popular language, with its known flaws, or a better language with those flaws fixed, one more to their taste and better suited to the machine it's being run on. The advantage of compiling an existing popular language is that you can run software written in that language. (If your compiler targets a new machine, as most machines were at the time one's-complement was still seen as a reasonable design choice for integers, this may be the only way you can run that software on that machine.) Unix was written on the PDP-7 in 1969, rewritten for the PDP-11 in I think 1972, and ported to the Interdata 7/32 at Wollongong and the Interdata 8/32 in New Jersey in 1977, the IBM 370 in 1977, the VAX in 1979 (32V), and the 68000 in 1982 (4.2BSD). Around that time Unix derivatives like XENIX (1984) started to spread the Gospel to the microcomputer world: the Z8000 and the 8086. Every single one of these processors was two's-complement. (I checked.) It seems unlikely to me that a C compiler written with the objective of running the existing body of Unix software, which is what was written in C at the time, would be able to get away with "we don't care, just invert the bits", because in practice most of the software you wanted to run would be written with the assumption that it was running on a two's-complement machine. There were some early "C" compilers that weren't compatible enough to compile Unix software — for example, BDS C (not BSD), now public domain, and the Tandem C compiler, for example, although those both ran on machines that happened to be two's-complement. But was there ever a C compiler that was sufficiently compatible to compile existing C software, but that implemented "~" as you suggest? Maybe, but I would be surprised.
- AnimalMuppet 6y agoThe first source I found online said that ~ was defined as the one's-complement operator and therefore had the effect of flipping bits. It's defined that way on all architectures, whether one's-complement, two's-complement, or something else. If you think about it, all of the bitwise operators had better be defined just in terms of the bits. Bitwise and, for example, had better be defined as the AND of the bits. No exceptions for the sign bits (or for anything else).
- 6y ago
- deleted 6y ago[deleted]