in reply to Why is this comparison failing?

Try replacing the data output line with:
warn sprintf "scale: %.40f\nscaled_index: %.40f\n" . "index: %.40f\nadjusted_hue: %.40f\n\n", $scale, $scaled_index, $index, $adjusted_hue;
then you'll see the following two outputs for the supposedly identical 0.3 cases:
adjusted_hue (75) equals 75 scale: 0.2999999999999999888977697537484345957637 scaled_index: 3.0000000000000000000000000000000000000000 index: 3.0000000000000000000000000000000000000000 adjusted_hue: 75.0000000000000000000000000000000000000000 adjusted_hue (75) does not equal 75 scale: 0.3000000000000000444089209850062616169453 scaled_index: 3.0000000000000004440892098500626161694527 index: 3.0000000000000000000000000000000000000000 adjusted_hue: 75.0000000000000142108547152020037174224854

Dave.

Replies are listed 'Best First'.
Re^2: Why is this comparison failing?
by johnrcomeau (Novice) on Oct 08, 2015 at 22:21 UTC
    Dave- Thanks. I should have known better. But I was misled by what I assumed was Perl's rules for how variables were used to build double-quoted strings. I would have thought that floating point numbers that are not integers would show enough decimal places to indicate such. That's how I was misled into thinking that these cases were identical. I realize that I actually don't know how numbers are evaluated for double-quoted strings. Do you have a good reference? Regards, John
      It's not really about string representation or integers. It may be more about the limits of Perl 5 and most programming languages in dealing with fractions and floating point. For example:
      perl -Mstrict -w -e 'if (0.3 == 0.1 * 3) { print "equals\n" } else { p +rint "* difference * ", abs(0.3 - 0.1 * 3), "\n" }' * difference * 5.55111512312578e-17
      Ron
      I'm not sure it's documented anywhere. The number of significant digits it uses varies by platform, but typically it stringifies a float to 15 significant digits, with trailing 0's excised.

      Dave.