Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: sub as mathematical function

by holli (Abbot)
on Sep 04, 2019 at 11:38 UTC ( #11105579=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    sub quant{
    # 14 characters, but I am bad at this, I'm sure it can get shorter
    int((shift)*8)
    }
    
  2. or download this
    sub quant{ int((shift)*8) }
    
    for ( 1 .. 9 ) {
        print "$_ => ", quant( ($_/9) - 0.0001 ), "\n";
    }
    
  3. or download this
    1 => 0
    2 => 1
    ...
    7 => 6
    8 => 7
    9 => 7  // BOOM!
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2021-04-17 11:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?