Monday 15 February 2010

Division by 1 in programming languages -


What will happen if we ask the programming language to compute it: X / 1, where X is a number Do they actually calculate the output or check / ignore and return XX?

In addition, when there is some coding like above, it is worth checking whether the divider is 1 or is it just faster to calculate the partition anyway?

Thanks


To expand this question: Which is faster?

  $ result = $ number / $ denominator;  

or

$ result = $ separator & gt; 1? $ Number / $ separator: $ number; Most programming languages ​​probably will not check with special exception (with the exception of 0). .

The CPU is fast on partition nowadays so it is not worth checking in advance. Check may take longer than actual division.


No comments:

Post a Comment