Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi, can this sub be expressed in a simple mathematical function like int(8*$v) that returns exactly the same?
sub quant { # input: float 0 to 1 inclusive my $v = shift; if ($v<1/9) { return 0 } elsif ($v<2/9) { return 1 } elsif ($v<3/9) { return 2 } elsif ($v<4/9) { return 3 } elsif ($v<5/9) { return 4 } elsif ($v<6/9) { return 5 } elsif ($v<7/9) { return 6 } elsif ($v<8/9) { return 7 } else { return 8 } }


Replies are listed 'Best First'.  

Re: sub as mathematical function
by LanX (Cardinal) on Sep 04, 2019 at 11:35 UTC  
by Anonymous Monk on Sep 04, 2019 at 12:29 UTC  
by LanX (Cardinal) on Sep 04, 2019 at 13:08 UTC  
by davido (Cardinal) on Sep 04, 2019 at 18:12 UTC  
by LanX (Cardinal) on Sep 04, 2019 at 21:15 UTC  
by rsFalse (Hermit) on Sep 04, 2019 at 17:06 UTC  
Re: sub as mathematical function
by holli (Abbot) on Sep 04, 2019 at 11:38 UTC  
by ikegami (Pope) on Sep 04, 2019 at 16:29 UTC  
Re: sub as mathematical function
by talexb (Canon) on Sep 04, 2019 at 13:47 UTC  
Re: sub as mathematical function
by Corion (Pope) on Sep 04, 2019 at 11:26 UTC  
by Anonymous Monk on Sep 04, 2019 at 11:34 UTC  
by Corion (Pope) on Sep 04, 2019 at 11:36 UTC  
Re: sub as mathematical function
by ikegami (Pope) on Sep 04, 2019 at 16:20 UTC  
by vr (Curate) on Sep 04, 2019 at 21:04 UTC 
Back to
Seekers of Perl Wisdom