http://www.perlmonks.org?node_id=11105576


in reply to Re: sub as mathematical function
in thread sub as mathematical function

sorry I dont get what you're saying :-( I tried floor(8*$x), round(8*$x), ceil(8*$x) from the POSIX module but their all different from the sub

Replies are listed 'Best First'.
Re^3: sub as mathematical function
by Corion (Pope) on Sep 04, 2019 at 11:36 UTC

    I linked to the documentation of the modulo operator. Your subroutine basically seems to do:

    sub mod_9 { my( $x ) = @_; return $x % 9 }

    Update: No, I misread the original function. You seem to input a number with decimals and want to know into which 9-tile it falls. int ($x*9)-1, as LanX notes below, is the correct answer then.