Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: place floats into array (Corrected.)

by BrowserUk (Pope)
on Sep 19, 2013 at 18:25 UTC ( #1054897=note: print w/replies, xml ) Need Help??


in reply to place floats into array

Perhaps the word you are missing is 'magnitude'.

Try this:

#! perl -slw use strict; sub log10{ log( $_[0] ) / log( 10 ) } sub magnitude{ int log10( $_[0] ) } sub sign { $_[0] <=> 0 } my @nums = sort{ $b <=> $a } qw[ 1.3e-3 3.7e-5 102 46 1e-4 1e-12 ]; my @byMag; my $prev = $nums[ 0 ]; for my $i ( 1 .. $#nums ) { my $this = $nums[ $i ]; my $diff = abs( magnitude( $prev ) - magnitude( $this ) ); --$diff if sign( magnitude( $this ) ) == sign( magnitude( $prev ) +); push @byMag, $prev; push @byMag, ( 0 ) x $diff if $diff > 1; $prev = $this; } push @byMag, $prev; print for @byMag; __END__ C:\test>1054890.pl 102 46 0 0 0 1.3e-3 1e-4 3.7e-5 0 0 0 0 0 0 1e-12

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: place floats into array
by keszler (Priest) on Sep 19, 2013 at 18:32 UTC
    Is there an emoticon for "light bulb over head"? This makes a lot more sense than my interpretation of the question.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1054897]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2016-12-04 12:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (64 votes). Check out past polls.