Sorting exponential numbers

Discussion in 'Perl Misc' started by Fabrice Baro, Feb 15, 2007.

  1. Fabrice Baro

    Fabrice Baro Guest

    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[...]00000999999999999999957534737399913078515638562734891876822570107876
    0.00[...]00010000000000000000015234388133035855383875390450151974382791625208
    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.
     
    Fabrice Baro, Feb 15, 2007
    #1
    1. Advertising

  2. Fabrice Baro

    Fabrice Baro Guest

    [embarrassed]
    Thanks Steven,
    I had indeed read this, but I went over the fact my sort was a
    "numerical" sort.
     
    Fabrice Baro, Feb 15, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eric Lawrence [MSFT]

    Re: See data in exponential format

    Eric Lawrence [MSFT], Mar 1, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    593
    =?Utf-8?B?Sm9yZ2UgTWFnYW50bw==?=
    Mar 2, 2004
  2. Exponential

    , Feb 10, 2005, in forum: C++
    Replies:
    1
    Views:
    1,014
    Victor Bazarov
    Feb 11, 2005
  3. Timothy Fitz

    Exponential Notation and integers

    Timothy Fitz, Nov 18, 2004, in forum: Python
    Replies:
    4
    Views:
    1,107
    =?ISO-8859-1?Q?F=E1bio?= Mendes
    Nov 19, 2004
  4. ruds
    Replies:
    3
    Views:
    488
  5. J.Sperlhofer
    Replies:
    9
    Views:
    309
    Dr John Stockton
    Apr 28, 2005
Loading...

Share This Page