Skip to content

Commit 175ceda

Browse files
committed
sort can support numbers with exponents
1 parent 5edb51e commit 175ceda

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/table.c

+19
Original file line numberDiff line numberDiff line change
@@ -1628,6 +1628,7 @@ cut_numeric_value(char *str, int xmin, int xmax, double *d, bool border0, bool *
16281628
bool only_digits = false;
16291629
bool only_digits_with_point = false;
16301630
bool skip_initial_spaces = true;
1631+
bool found_exponent = false;
16311632
int x = 0;
16321633

16331634
char decimal_point = '\0';
@@ -1748,6 +1749,23 @@ cut_numeric_value(char *str, int xmin, int xmax, double *d, bool border0, bool *
17481749
}
17491750
else if (!isdigit(c))
17501751
{
1752+
if (c == 'e' && !found_exponent && chrlen == 1 && decimal_point != '\0')
1753+
{
1754+
/* try to skip e+n */
1755+
if (str[1] == '+' || str[1] == '-')
1756+
{
1757+
if (isdigit(str[2]))
1758+
{
1759+
found_exponent = true;
1760+
memcpy(buffptr, str, 3);
1761+
str += 3;
1762+
x += 3;
1763+
buffptr += 3;
1764+
continue;
1765+
}
1766+
}
1767+
}
1768+
17511769
only_digits = false;
17521770
only_digits_with_point = false;
17531771
}
@@ -1821,6 +1839,7 @@ cut_numeric_value(char *str, int xmin, int xmax, double *d, bool border0, bool *
18211839
}
18221840

18231841
errno = 0;
1842+
18241843
*d = strtod(buffer, NULL);
18251844
if (errno == 0)
18261845
{

0 commit comments

Comments
 (0)