in reply to Normalise numbers

If $max = $min, shouldn't you scale all the numbers to 1? So scale should be set to either $max or $min.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re^2: Normalise numbers
by GrandFather (Saint) on Nov 04, 2005 at 21:46 UTC

    You spotted the bug, but not the solution. You can't "scale" 0 to 1, you have to offset it. To handle that you would need to add another test to the code and adjust $min in the $min == $max special case:

    $min -= 1 if $min == $max;

    You can however offset anything to 0, so the bug fix has that result.


    Perl is Huffman encoded by design.