R
robert maas, see http://tinyurl.com/uh3t
(second attempt)
I'm just a beginner at perl. Currently I'm comparing how integers are
supported in several different programming languages:
<http://www.rawbw.com/~rem/HelloPlus/CookBook/CookTop.html#int>
I wrote a test program in perl, but it gives inconsistent results.
Here's the program source:
#!/usr/bin/perl
$a = 'Hello';
$b = 'world.';
$all = "$a $b";
print "$all\n"; # Print a message
$n = 987654321;
print "n = $n\n";
$k = 1000000000000000000000000000000000000000000000000000000000000000000000;
$n = $n * $k;
print "n = $n\n";
$k = $k * $k;
$n = $n * $k;
print "n = $n\n";
$n1 = $n * $k;
print "n1 = $n1\n";
$k = 1000000000000000000000000000000000000000000000000000000000000000000000;
$n1 = $n * $k;
print "n1 = $n1\n";
and here's the program output:
Hello world.
n = 987654321
n = 9.87654321e+77
n = 9.87654321e+215
n1 = Inf
n1 = 9.87654321e+284
Notice the two printings of n1. The first time I multiply the value
of n times the value of k that I've been using all along, and the
result is infinity. The second time, I re-assign the value of k to
identical value as it had before, and do the same multiplication as
before, but now the result isn't infinity. What's going on??? This
doesn't make sense to me.
If it makes any difference:
perl -v
This is perl, v5.8.0 built for i386-freebsd
I'm just a beginner at perl. Currently I'm comparing how integers are
supported in several different programming languages:
<http://www.rawbw.com/~rem/HelloPlus/CookBook/CookTop.html#int>
I wrote a test program in perl, but it gives inconsistent results.
Here's the program source:
#!/usr/bin/perl
$a = 'Hello';
$b = 'world.';
$all = "$a $b";
print "$all\n"; # Print a message
$n = 987654321;
print "n = $n\n";
$k = 1000000000000000000000000000000000000000000000000000000000000000000000;
$n = $n * $k;
print "n = $n\n";
$k = $k * $k;
$n = $n * $k;
print "n = $n\n";
$n1 = $n * $k;
print "n1 = $n1\n";
$k = 1000000000000000000000000000000000000000000000000000000000000000000000;
$n1 = $n * $k;
print "n1 = $n1\n";
and here's the program output:
Hello world.
n = 987654321
n = 9.87654321e+77
n = 9.87654321e+215
n1 = Inf
n1 = 9.87654321e+284
Notice the two printings of n1. The first time I multiply the value
of n times the value of k that I've been using all along, and the
result is infinity. The second time, I re-assign the value of k to
identical value as it had before, and do the same multiplication as
before, but now the result isn't infinity. What's going on??? This
doesn't make sense to me.
If it makes any difference:
perl -v
This is perl, v5.8.0 built for i386-freebsd