Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>About your edit, the language says nothing about the architecture it's running on. Your question is platform dependent.</p> <p>That said, typically all fundamental data-type operations have a one-to-one correspondence to assembly.</p> <p>x86 for example has an instruction which increments a value by 1, which <code>i++</code> or <code>i += 1</code> would translate into. Addition and multiplication also have single instructions.</p> <p>Hardware-wise, it's fairly obvious that adding or multiplying numbers is at least linear in the number of bits in the numbers. Because the hardware has a constant number of bits, it's O(1).</p> <p>Floats have their own processing unit, usually, which also has single instructions for operations.</p> <hr> <p>Does it matter?</p> <p>Why not write the code that does what you need it to do. If you want to add one, use ++. If you want to add a large number, add a large number. If you need floats, use floats. If you need to multiply two numbers, then multiply them.</p> <p>The compiler will figure out the best way to do what you want, so instead of trying to be tricky, do what you need and let it do the hard work.</p> <p>After you've written your working code, and you decide it's too slow, <strong>profile</strong> it and find out why. You'll find it's not silly things like multiplying versus adding, but rather going about the entire (sub-)problem in the wrong way.</p> <p>Practically, all of the operators you listed will be done in a single CPU instruction anyway, on desktop platforms.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload