mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-28 00:21:56 +00:00
Fix for 1028710: floor() fails on floor(log(1000)/log(10))
This commit is contained in:
@@ -6876,7 +6876,7 @@ sub distro_sparkline {
|
||||
|
||||
$min = 0 if $min == $max;
|
||||
my @range_min;
|
||||
my $d = floor(($max-$min) / 4);
|
||||
my $d = floor((($max+0.00001)-$min) / 4);
|
||||
for my $x ( 1..4 ) {
|
||||
push @range_min, $min + ($d * $x);
|
||||
}
|
||||
|
@@ -3946,7 +3946,7 @@ sub _chunk_char {
|
||||
}
|
||||
|
||||
my $n_chunks = $args{rows_in_range} / $args{chunk_size};
|
||||
my $interval = floor($n_values / $n_chunks) || 1;
|
||||
my $interval = floor(($n_values+0.00001) / $n_chunks) || 1;
|
||||
|
||||
my $range_func = sub {
|
||||
my ( $self, $dbh, $start, $interval, $max ) = @_;
|
||||
@@ -4440,7 +4440,7 @@ sub base_count {
|
||||
|
||||
return $symbols->[0] if $n == 0;
|
||||
|
||||
my $highest_power = floor(log($n)/log($base));
|
||||
my $highest_power = floor(log($n+0.00001)/log($base));
|
||||
if ( $highest_power == 0 ){
|
||||
return $symbols->[$n];
|
||||
}
|
||||
@@ -4452,11 +4452,10 @@ sub base_count {
|
||||
|
||||
my @base_multiples;
|
||||
foreach my $base_power ( reverse @base_powers ) {
|
||||
my $multiples = floor($n / $base_power);
|
||||
my $multiples = floor(($n+0.00001) / $base_power);
|
||||
push @base_multiples, $multiples;
|
||||
$n -= $multiples * $base_power;
|
||||
}
|
||||
|
||||
return join('', map { $symbols->[$_] } @base_multiples);
|
||||
}
|
||||
|
||||
|
@@ -5366,7 +5366,7 @@ sub _chunk_char {
|
||||
}
|
||||
|
||||
my $n_chunks = $args{rows_in_range} / $args{chunk_size};
|
||||
my $interval = floor($n_values / $n_chunks) || 1;
|
||||
my $interval = floor(($n_values+0.00001) / $n_chunks) || 1;
|
||||
|
||||
my $range_func = sub {
|
||||
my ( $self, $dbh, $start, $interval, $max ) = @_;
|
||||
@@ -5860,7 +5860,7 @@ sub base_count {
|
||||
|
||||
return $symbols->[0] if $n == 0;
|
||||
|
||||
my $highest_power = floor(log($n)/log($base));
|
||||
my $highest_power = floor(log($n+0.00001)/log($base));
|
||||
if ( $highest_power == 0 ){
|
||||
return $symbols->[$n];
|
||||
}
|
||||
@@ -5872,11 +5872,10 @@ sub base_count {
|
||||
|
||||
my @base_multiples;
|
||||
foreach my $base_power ( reverse @base_powers ) {
|
||||
my $multiples = floor($n / $base_power);
|
||||
my $multiples = floor(($n+0.00001) / $base_power);
|
||||
push @base_multiples, $multiples;
|
||||
$n -= $multiples * $base_power;
|
||||
}
|
||||
|
||||
return join('', map { $symbols->[$_] } @base_multiples);
|
||||
}
|
||||
|
||||
|
@@ -811,7 +811,7 @@ sub distro_sparkline {
|
||||
# Divide the range by 4 because there are 4 char codes: _.-^
|
||||
$min = 0 if $min == $max;
|
||||
my @range_min;
|
||||
my $d = floor(($max-$min) / 4);
|
||||
my $d = floor((($max+0.00001)-$min) / 4);
|
||||
for my $x ( 1..4 ) {
|
||||
push @range_min, $min + ($d * $x);
|
||||
}
|
||||
|
@@ -665,7 +665,7 @@ sub _chunk_char {
|
||||
# 2 chars to express enough vals for 1 chunk, then we'll increment through
|
||||
# the map 2 chars at a time, like [a, b], [c, d], etc.
|
||||
my $n_chunks = $args{rows_in_range} / $args{chunk_size};
|
||||
my $interval = floor($n_values / $n_chunks) || 1;
|
||||
my $interval = floor(($n_values+0.00001) / $n_chunks) || 1;
|
||||
|
||||
my $range_func = sub {
|
||||
my ( $self, $dbh, $start, $interval, $max ) = @_;
|
||||
@@ -1382,7 +1382,7 @@ sub base_count {
|
||||
# zeroth symbol in any other base.
|
||||
return $symbols->[0] if $n == 0;
|
||||
|
||||
my $highest_power = floor(log($n)/log($base));
|
||||
my $highest_power = floor(log($n+0.00001)/log($base));
|
||||
if ( $highest_power == 0 ){
|
||||
return $symbols->[$n];
|
||||
}
|
||||
@@ -1394,11 +1394,10 @@ sub base_count {
|
||||
|
||||
my @base_multiples;
|
||||
foreach my $base_power ( reverse @base_powers ) {
|
||||
my $multiples = floor($n / $base_power);
|
||||
my $multiples = floor(($n+0.00001) / $base_power);
|
||||
push @base_multiples, $multiples;
|
||||
$n -= $multiples * $base_power;
|
||||
}
|
||||
|
||||
return join('', map { $symbols->[$_] } @base_multiples);
|
||||
}
|
||||
|
||||
|
@@ -1358,6 +1358,23 @@ is_deeply(
|
||||
"Caclulate chunks for `key` col (bug 967451)"
|
||||
);
|
||||
|
||||
# #############################################################################
|
||||
# base_count fails on n = 1000, base = 10
|
||||
# https://bugs.launchpad.net/percona-toolkit/+bug/1028710
|
||||
# #############################################################################
|
||||
|
||||
my $res = TableChunker->base_count(
|
||||
count_to => 1000,
|
||||
base => 10,
|
||||
symbols => ["a".."z"],
|
||||
);
|
||||
|
||||
is(
|
||||
$res,
|
||||
"baaa",
|
||||
"base_count's floor()s account for floating point arithmetics",
|
||||
);
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
|
Reference in New Issue
Block a user