develooper Front page | perl.perl5.porters | Postings from March 2001

Re: [ID 20010305.005] "use integer" doesn't make rand() return integers

Thread Previous | Thread Next
John Peacock
March 7, 2001 07:22
Re: [ID 20010305.005] "use integer" doesn't make rand() return integers
Message ID: wrote:
> On Tue, Mar 06, 2001 at 02:08:02PM -0500, John Peacock wrote:
> > Since 'use integer' strictly affects mathematic operations, not
> > mathematic functions, I think this is not a good enhancement.
> Could you please, from a mathematical viewpoint, tell me what the
> difference is between an operator and a function? Even from a CS
> standpoint, the only differences are syntactical details, only relevant
> to parsing tables, and largely artificial.
> Abigail

It is not a matter of mathematics, it is a matter of which underlying
math library Perl is going to apply.

use integer;
my $float=1.434;
my $int = 12;

$int += 4.5;	# $int is now 16, not 16.5
$int += $float;	# $int is now 17
$float += 1;	# $float is now 2 (an integer)

$float = sin(30);# $float is now -0.988031624092862 (not an integer)
print $int, "\t", $float, "\n";

sin, tan, rand, etc are mathematic functions contained within the 
underlying floating point math library.  "use integer" has no impact
on them, nor IMHO should it.  The math operations +, -, *, / are
affected by "use integer" because the value is cast to an integer
and the integer math functions are used.  That is the point of 
"use integer" after all.  There is really no point in extending it
to rand (and certainly no point in applying it to sin, tan, etc).

John Peacock

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About