Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
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?
[holli]: good morning you beautiful people. happy last work week of 2017

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2017-12-18 04:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (467 votes). Check out past polls.

    Notices?