Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: sub as mathematical function

by Corion (Patriarch)
on Sep 04, 2019 at 11:26 UTC ( [id://11105574]=note: print w/replies, xml ) Need Help??


in reply to sub as mathematical function

Yes, see the "modulo" or "remainder" operator.

Replies are listed 'Best First'.
Re^2: sub as mathematical function
by Anonymous Monk on Sep 04, 2019 at 11:34 UTC
    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

      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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (8)
As of 2024-04-19 08:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found