3 ms·
Perhaps thinking about it as an optimisation and not a standard operation is not the best way to look at it. For example 99% of the time I want a binary shift
by hrktb 14y ago
Perhaps thinking about it as an optimisation and not a standard operation is not the best way to look at it.
For example 99% of the time I want a binary shift and not a /2.In a dynamically typed language 201/2 will give you 100.5 when you'd prefer to keep it integer.
- pwaring 14y ago"In a dynamically typed language 201/2 will give you 100.5" Not necessarily. Python gives 100, PHP gives 100.5, Perl gives 100.5, Ruby gives 100. Edit: Versions are Python 2.7.3, PHP 5.3.10, Perl 5.14.2 and Ruby 1.8.7, all as shipped with Ubuntu Precise.
- archangel_one 14y agoPython 3 gives 100.5. Python 2 gives 100 (or 100.5 if you use "from __future__ import division").
- fjh 14y agoBut using >> for division is still a bad idea. If you want integer division, use //.
- wglb 14y agoUm, no. Lisp will give you 201/2.