Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Math function

Status
Not open for further replies.

aj2taylo

Programmer
Nov 4, 2002
17
CA
Hey,

I have been looking around and having trouble finding if a MOD math function, eg. 8 mod 5 = 3. Does anyone know if this exists?

Thanks
 
All perl operators are documented in the perlop man page.

This page contains:

Multiplicative Operators

Binary "*" multiplies two numbers.

Binary "/" divides two numbers.

Binary "%" computes the modulus of two numbers.

Given integer operands $a and $b: If $b is positive, then "$a % $b" is $a minus the largest multiple of $b that is not greater than $a. If $b is negative, then "$a % $b" is $a minus the smallest multiple of $b that is not less than $a (i.e. the result will be less than or equal to zero). Note than when "use integer" is in scope, "%" gives you direct access to the modulus operator as implemented by your C compiler. This operator is not as well defined for negative operands, but it will execute faster.

Yours, "As soon as we started programming, we found to our surprise that it wasn't as
easy to get programs right as we had thought. Debugging had to be discovered.
I can remember the exact instant when I realized that a large part of my life
from then on was going to be spent in finding mistakes in my own programs."
--Maurice Wilk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top