Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Sign bug in Number::Format

by Anonymous Monk
on Jun 05, 2012 at 20:00 UTC ( #974538=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Is this a bug? Looks like a bug, but wanted to confirm here before I go and report a bug...
DB<1> use Number::Format; DB<2> print Number::Format::format_number(-0.00004,5) 4e-05

Replies are listed 'Best First'.
Re: Sign bug in Number::Format
by toolic (Bishop) on Jun 05, 2012 at 20:23 UTC
    The POD for Number::Format mentions a format_negative function. I don't think format_number handles negative numbers, by design.

    UPDATE: Nevermind... this prints a negative value:

    print Number::Format::format_number(-0.0004,5)
Re: Sign bug in Number::Format
by herveus (Parson) on Jun 05, 2012 at 20:13 UTC

    What were you expecting to get? A quick glance at the module documentation suggests that the output is what should have come out.

      He would expect a negative number. It does look like a bug.
Re: Sign bug in Number::Format
by Anonymous Monk on Jun 06, 2012 at 01:46 UTC
Re: Sign bug in Number::Format (Devel::DumpTrace)
by toolic (Bishop) on Jun 10, 2012 at 00:35 UTC
    I believe Devel::DumpTrace quickly identifies the root cause of the problem.
    perl -d:DumpTrace=+Number::Format -MNumber::Format -E 'say Number::For +mat::format_number(-0.00004, 5)' >>> -e:1:[__top__]: say Number::Format::format_number(-0.00004, 5 +) >>> Number/[_get_self]: unless (ref $_:(-4e-05,5)[0 +] && UNIVERSAL::isa($_:(-4e-05,5)[0], "Number::Format"))

    It seems that perl immediately interprets the value passed to the function (-0.00004) as scientific notation inside the function (-4e-05). A diff of this output vs. the output of a passing case with one less zero (-0.0004) shows where in the code the 2 cases diverge. I uploaded a patch to the open bug report.

    It then occurred to me to take a look a the coverage results ( new web site for CPAN code coverage). Sure enough, the line of code I patched was not covered by the test suite. This shows the value in using coverage to determine test quality.

    Morals of this story:

Re: Sign bug in Number::Format
by ww (Archbishop) on Jun 05, 2012 at 20:54 UTC
    Bug? It looks correct to me:
    4 x 10^-5 = 0.00004
    and 0.00004 = 4 x 10^-5 or 4e-05
    Ooops (ikegami & toolic bring me to my senses):
    DB<3> print Number::Format::format_number(-0.0004,5)

    Peripheral note: strikeout makes "=" look like -.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://974538]
Approved by herveus
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2017-12-17 09:25 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (462 votes). Check out past polls.