my @tbl = ( 0.5, 0.25, 0.125, 0.0625, 0.03125, 0.015625, 0.0078125, 0.00390625, 0.001953125, 0.0009765625, 0.00048828125, 0.000244140625, 0.0001220703125, 0.00006103515625, 0.000030517578125, 0.0000152587890625 ); my $step = 0.001; my $fmt = "%.3f : 0.%s : 0.%s : 0.%s : 0.%s : %.8f : %.10f : %.12f : %.16f\n"; my @acm; my @cal; my @bin; my $scaleidx; for(my $i = 0; $i < 1; $i += $step) { @cal = ( $i, $i, $i, $i); @acm = ( 0 , 0, 0, 0 ); @bin = ( "", "", "", ""); $scaleidx = 4; for(my $m = 0; $m < @tbl; $m++) { if ($m > 7) { $scaleidx = 3; } if ($m > 9) { $scaleidx = 2; } if ($m > 11) { $scaleidx = 1; } for(my $idx = 0; $idx < $scaleidx; $idx++) { $cal[$idx] = $cal[$idx] * 2; if ($cal[$idx] >= 1) { $acm[$idx] += $tbl[$m]; $cal[$idx] -= 1; $bin[$idx] .= "1"; } else { $bin[$idx] .= "0"; } } } printf($fmt, $i, $bin[3], $bin[2], $bin[1], $bin[0], $acm[3], $acm[2], $acm[1], $acm[0]); }