LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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

Reply
 
Search this Thread
Old 01-22-2011, 05:42 AM   #1
kaz2100
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,436

Rep: Reputation: 83
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
 
Old 01-22-2011, 09:53 AM   #2
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942
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.
 
Old 01-22-2011, 10:17 AM   #3
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,755

Rep: Reputation: 466Reputation: 466Reputation: 466Reputation: 466Reputation: 466
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:
Code:
sort -n testsort
 
Old 01-22-2011, 11:28 AM   #4
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942
@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.
 
Old 01-23-2011, 06:12 AM   #5
kaz2100
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,436

Original Poster
Rep: Reputation: 83
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!
 
  


Reply

Tags
coreutils, digits, precision, sort


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Newbie - what to do about huge number attempted ssh logins cnmoore Linux - Security 25 09-16-2010 07:12 AM
Tellico: Is there a way to sort by comic book issue number? Rockgod1969 Linux - Software 2 09-18-2009 08:20 AM
powertop reporting a huge number of acpi interrupts gawhelan Linux - Laptop and Netbook 5 01-15-2009 02:12 AM
Problem with huge number of pthreads Berng Programming 7 12-17-2003 07:33 AM
xmms: sort by track number ianunderwood Linux - Software 1 08-16-2003 03:33 PM


All times are GMT -5. The time now is 01:16 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration