in reply to Re^6: &1 is no faster than %2 when checking for oddness. Oh well. (best)
in thread &1 is no faster than %2 when checking for oddness. Oh well.
To make it extremely simple, consider the code:
At last, a technical argument. For safety.
This
sub odd { die 'Out of integer range' if $_[ 0 ] & 0xffffffff != $_[ 0 ]; ## Should be done by perl! return $_[ 0 ] & 1; }
Versus this
sub odd { my $num= shift @ARGV; die 'Number too big to test for oddness' if $num > 9_007_199_254_740__992; die 'Number too small to test for oddness' if $num < -9_007_199_254_740__992; die 'Cannot test #INFinity for oddness' if $num eq '1.#INF'; die 'Cannot test negative #INFinity for oddness' if $num eq '-1.#INF'; die 'Cannot test #IND for oddness' if $num eq '1.#IND'; die 'Cannot test negative #IND for oddness' if $num eq '-1.#IND'; die 'Cannot test a non number for oddness' if $num eq '1.#QNAN; die 'Cannot test negative non number for oddness' if $num eq '-1.#QNAN; die 'Cannot test a non-integer for oddness' if int( $num ) != $num; return $num % 2 ? 1 : 0; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: &1 is no faster than %2 when checking for oddness. Oh well. (odd)
by tye (Sage) on Nov 17, 2006 at 11:59 UTC | |
|