Recode the naughty binary bytes ([\x00-\x08\x0b-\x1f\x7f-\xff])
[p5sagit/p5-mst-13.2.git] / lib / integer.pm
CommitLineData
a0d0e21e 1package integer;
2
b75c8c73 3our $VERSION = '1.00';
4
f06db76b 5=head1 NAME
6
7integer - Perl pragma to compute arithmetic in integer instead of double
8
9=head1 SYNOPSIS
10
11 use integer;
12 $x = 10/3;
13 # $x is now 3, not 3.33333333333333333
14
15=head1 DESCRIPTION
16
a3cb178b 17This tells the compiler to use integer operations
f06db76b 18from here to the end of the enclosing BLOCK. On many machines,
19this doesn't matter a great deal for most computations, but on those
20without floating point hardware, it can make a big difference.
21
a3cb178b 22Note that this affects the operations, not the numbers. If you run this
23code
24
25 use integer;
26 $x = 1.5;
27 $y = $x + 1;
28 $z = -1.5;
29
30you'll be left with C<$x == 1.5>, C<$y == 2> and C<$z == -1>. The $z
31case happens because unary C<-> counts as an operation.
32
47f6b1df 33Native integer arithmetic (as provided by your C compiler) is used.
34This means that Perl's own semantics for arithmetic operations may
35not be preserved. One common source of trouble is the modulus of
36negative numbers, which Perl does one way, but your hardware may do
37another.
38
39 % perl -le 'print (4 % -3)'
40 -2
41 % perl -Minteger -le 'print (4 % -3)'
42 1
43
f06db76b 44See L<perlmod/Pragmatic Modules>.
45
46=cut
47
d5448623 48$integer::hint_bits = 0x1;
49
a0d0e21e 50sub import {
d5448623 51 $^H |= $integer::hint_bits;
a0d0e21e 52}
53
54sub unimport {
d5448623 55 $^H &= ~$integer::hint_bits;
a0d0e21e 56}
57
581;