Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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> 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.

Comment on Re: place floats into array (Corrected.)
Download Code
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1054897]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (11)
As of 2015-11-30 19:43 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (778 votes), past polls