Mailing List Archive

Bug Report: Expotential numbers don't work with "x" operator
Expotential numbers (like 1e1) aren't converted correctly when used with
the "x" operator. The number is truncated at the "e". This did work
with Perl 4.x:

Example:

$number = "1e1"; #imagine this as chop($number = <STDIN>)
$string = "a";
print "$string" x $number, "\n";

In Perl 4.x, it prints "aaaaaaaaaa", In Perl5.0, it prints only "a".

However, the following two do work in both Perl4.x and Perl5.0:

$number = 1e1; #Works, but can't enter it from <STDIN>
$string = "a";
print "$string" x $number, "\n";

$number = "1e1";
$string = "a";
$number = $number + 0; #1e1 is converted first
print "$string" x $number, "\n";

--
David Weintraub _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
System Configuration Management _/ _/
Dow Jones/Telerate - NSG _/ I AM THE GREAT AND POWERFUL OZ* _/
dhw@telerate.com _/ _/
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
*Pay no attention to the man behind the curtains.
Re: Bug Report: Expotential numbers don't work with "x" operator [ In reply to ]
>>>>> "David" == David Weintraub <dhw@serah.telerate.com> writes:


David> Expotential numbers (like 1e1) aren't converted correctly when used with
David> the "x" operator. The number is truncated at the "e". This did work
David> with Perl 4.x:

David> Example:

David> $number = "1e1"; #imagine this as chop($number = <STDIN>)
David> $string = "a";
David> print "$string" x $number, "\n";

David> In Perl 4.x, it prints "aaaaaaaaaa", In Perl5.0, it prints only "a".

Operating on the theory that when an implicit-string-to-int conversion
is performed, it was using atoi() instead of (int) atof(), this bug
*also* surfaced in testing a moment ago:

@a = (0..100);
print $a["1e1"]; # should print 10, but prints 1!

Again, 4.036 gives the proper results, and perl5 bugs out.

(A background in QA testing helps. :-)

So, from a black-box point of view, I'd say that the widget that turns
strings into numbers when *ints* are required was trying to take a
shortcut, and the shortcut was thornier and more impassable than was
first expected.

Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.teleport.com/~merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me