home *** CD-ROM | disk | FTP | other *** search
-
- <HTML>
- <HEAD>
- <TITLE>integer - Perl pragma to compute arithmetic in integer instead of double</TITLE>
- <LINK REL="stylesheet" HREF="../Active.css" TYPE="text/css">
- <LINK REV="made" HREF="mailto:">
- </HEAD>
-
- <BODY>
- <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
- <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
- <STRONG><P CLASS=block> integer - Perl pragma to compute arithmetic in integer instead of double</P></STRONG>
- </TD></TR>
- </TABLE>
-
- <A NAME="__index__"></A>
- <!-- INDEX BEGIN -->
-
- <UL>
-
- <LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
-
- <LI><A HREF="#synopsis">SYNOPSIS</A></LI>
- <LI><A HREF="#description">DESCRIPTION</A></LI>
- </UL>
- <!-- INDEX END -->
-
- <HR>
- <P>
- <H1><A NAME="name">NAME</A></H1>
- <P>integer - Perl pragma to compute arithmetic in integer instead of double</P>
- <P>
- <HR>
- <H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
- <UL>
- <LI>Linux</LI>
- <LI>Solaris</LI>
- <LI>Windows</LI>
- </UL>
- <HR>
- <H1><A NAME="synopsis">SYNOPSIS</A></H1>
- <PRE>
- use integer;
- $x = 10/3;
- # $x is now 3, not 3.33333333333333333</PRE>
- <P>
- <HR>
- <H1><A NAME="description">DESCRIPTION</A></H1>
- <P>This tells the compiler to use integer operations
- from here to the end of the enclosing BLOCK. On many machines,
- this doesn't matter a great deal for most computations, but on those
- without floating point hardware, it can make a big difference.</P>
- <P>Note that this affects the operations, not the numbers. If you run this
- code</P>
- <PRE>
- use integer;
- $x = 1.5;
- $y = $x + 1;
- $z = -1.5;</PRE>
- <P>you'll be left with <CODE>$x == 1.5</CODE>, <CODE>$y == 2</CODE> and <CODE>$z == -1</CODE>. The $z
- case happens because unary <CODE>-</CODE> counts as an operation.</P>
- <P>Native integer arithmetic (as provided by your C compiler) is used.
- This means that Perl's own semantics for arithmetic operations may
- not be preserved. One common source of trouble is the modulus of
- negative numbers, which Perl does one way, but your hardware may do
- another.</P>
- <PRE>
- % perl -le 'print (4 % -3)'
- -2
- % perl -Minteger -le 'print (4 % -3)'
- 1</PRE>
- <P>See <A HREF="../lib/Pod/perlmod.html#pragmatic modules">Pragmatic Modules in the perlmod manpage</A>.</P>
- <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
- <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
- <STRONG><P CLASS=block> integer - Perl pragma to compute arithmetic in integer instead of double</P></STRONG>
- </TD></TR>
- </TABLE>
-
- </BODY>
-
- </HTML>
-