Count the number of set bits in a 32-bit integer

This is known as the ‘Hamming Weight‘, ‘popcount’ or ‘sideways addition’. Some CPUs have a single built-in instruction to do it and others have parallel instructions which act on bit vectors. Instructions like x86’s popcnt (on CPUs where it’s supported) will almost certainly be fastest for a single integer. Some other architectures may have a … Read more

What is the rationale for all comparisons returning false for IEEE754 NaN values?

I was a member of the IEEE-754 committee, I’ll try to help clarify things a bit. First off, floating-point numbers are not real numbers, and floating-point arithmetic does not satisfy the axioms of real arithmetic. Trichotomy is not the only property of real arithmetic that does not hold for floats, nor even the most important. … Read more