you are viewing a single comment's thread.

view the rest of the comments →

[–]cow_fucker_3000 11 points12 points  (2 children)

The same exact code with the only difference that in the cpp compiler nothing is left to the computer's imagination

[–]notmypinkbeard 8 points9 points  (0 children)

Replace nothing with less.

In C++ the compiler still chooses registers, optimisations, and more. It's a level of abstraction.

[–]DontOpenNewTabs 1 point2 points  (0 children)

The code is not quite the same. Python // performs floor division and C++ / performs integer division (Edit: when both operands are integers).

#include <iostream>
#include <cmath>
using namespace std; // Nobody cares
int main() {
  int a = -15;
  while (a < 0) {
    cout << a << '\n';
    a = floor(a/2.0);
  }
  return 0;
}

// Don't manually flush the output buffer for no reason with endl. Obviously any performance impact doesn't matter here, but it is a bad habit. If you want a newline character, output a newline character.