Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
01-22-2011, 05:42 AM
|
#1
|
|
Senior Member
Registered: Apr 2005
Location: Penguin land, with apple, no gates
Distribution: Debian testing woody(32) sarge etch lenny squeeze(+64) wheezy jessie
Posts: 1,333
Rep:
|
sort -n, huge number
Hya,
Question
With 'sort -n': How huge can numbers be?
So far, I did
1. Check man page (info page as well) -> Not quite informative. (locale may be important.)
2. Experiment
Code:
>cat testsort
1
11111
11111111111111
111111111111111111111
1111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111110
0.1
0.000000000000000000001
000.1
100.001
100.1
1.0
1.0001
1
1.00000000000000000000000000000000000000000000000000000000000000000000000000
1.00
> cat testsort | sort -n
0.000000000000000000001
000.1
0.1
1
1
1.0
1.00
1.00000000000000000000000000000000000000000000000000000000000000000000000000
1.0001
100.001
100.1
11111
11111111111111
111111111111111111111
1111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111110
11111111111111111111111111111111111111111111111111
>
It looks good, except for (unnecessary) leading and trailing zero.
Does anybody know the answer?
Happy Penguins!
Last edited by kaz2100; 01-22-2011 at 06:29 AM.
Reason: typo
|
|
|
|
01-22-2011, 09:53 AM
|
#2
|
|
Senior Member
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
|
The general_numcompare() function in sort from coreutils-8.9 converts the numbers to the native long double type using the standard strtold() library function. This is used when the -g option is used.
Option -n uses strnumcmp() defined in coreutils-8.9/lib/strnumcmp-in.h, which does not do any numerical conversions. It is purely string-based, and should be able to compare any decimal number strings that fit into memory.
I sincirely hope this was not homework, Nominal Animal
Last edited by Nominal Animal; 03-21-2011 at 06:03 AM.
|
|
|
|
01-22-2011, 10:17 AM
|
#3
|
|
Amigo developer
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,593
|
I'd guess they would be limited by something like MAX_LINE -probably at least 1024 chars long -or by how much RAM you have for storing it all. You could do without the 'cat' command for faster results:
|
|
|
|
01-22-2011, 11:28 AM
|
#4
|
|
Senior Member
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
|
@gnashley: Some sort implementations may have line length limits, but not GNU sort from the coreutils package. From info sort:
Quote:
|
GNU `sort' (as specified for all GNU utilities) has no limit on input line length or restrictions on bytes allowed within lines. In addition, if the final byte of an input file is not a newline, GNU `sort' silently supplies one. A line's trailing newline is not part of the line for comparison purposes.
|
So yes, the limit seems to be the available memory (RAM + swap, or resource limits, whichever are smaller). Nominal Animal
Last edited by Nominal Animal; 03-21-2011 at 06:03 AM.
|
|
|
|
01-23-2011, 06:12 AM
|
#5
|
|
Senior Member
Registered: Apr 2005
Location: Penguin land, with apple, no gates
Distribution: Debian testing woody(32) sarge etch lenny squeeze(+64) wheezy jessie
Posts: 1,333
Original Poster
Rep:
|
Hya
thanks!
My bad! I did not think of checking the source code.
This is not my homework, it is rather my job (second job). Now I feel good.
The other day, I hit the size limit of long long int in C. Of course, it did not happen in test run, and it took several days to debug. I won't run into similar problem.
Happy Penguins!
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 03:35 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|