I don't know what I was thinking. Clearly, the simplicity of the error code is the best measure of how useful a subroutine is. So a better oddness tester would surely be:
sub odd { return 1 if "1" eq $_[0]; die "Can't test the oddness of anything but '1'.\n"; }
But then, neither of these are any more complicated than your first one:
sub odd { my $num= shift @_; die "Out of range" if 2**52 <= abs($num); return $num % 2; } sub odd { my $num= shift @_; die "Out of range" if 1 != (1+$num)-$num; return $num % 2; }
Update: For anyone who cares, I'm done. As is, this is a lot of noise for something pretty trivial and it is going nowhere slow.
- tye
In reply to Re^8: &1 is no faster than %2 when checking for oddness. Oh well. (odd)
by tye
in thread &1 is no faster than %2 when checking for oddness. Oh well.
by diotalevi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |