Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Sorting exponential numbers

Reply
Thread Tools

Sorting exponential numbers

 
 
Fabrice Baro
Guest
Posts: n/a
 
      02-15-2007
I'm trying to sort a hash whose values are exponential numbers.

foreach my $file (sort values %{$files{$brh}}){
print "$file\n";
}
prints:
0
1e-101
1e-103
1e-104

I've tried storing those numbers under regular notation by using
sprintf to convert: but it's impractical and seems not exact:
here are some of the numbers I obtain:
0.00[...]00000999999999999999957534737399913078515638562734 891876822570107876
0.00[...]00010000000000000000015234388133035855383875390450 151974382791625208
where the numbers should be 0.00[...]0001. Obviously there are some
conversion issues.

I think one solution could be to write a custom compare block or
function, but I'd rather use a builtin feature of sort. However I
haven't found such a feature in the perl FAQ nor in the groups.

 
Reply With Quote
 
 
 
 
Fabrice Baro
Guest
Posts: n/a
 
      02-15-2007
[embarrassed]
Thanks Steven,
I had indeed read this, but I went over the fact my sort was a
"numerical" sort.

 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble in comparing exponential numbers. ruds Java 3 06-12-2007 02:44 PM
Question: Exponential Notation and binary numbers (>e+61) J.Sperlhofer Javascript 9 04-28-2005 09:25 PM
Exponential diegoandrade@gmail.com C++ 1 02-11-2005 03:18 AM
Exponential Notation and integers Timothy Fitz Python 4 11-19-2004 02:28 AM
Re: See data in exponential format Eric Lawrence [MSFT] ASP .Net 3 03-02-2004 10:26 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57