ManeXi Posted March 9, 2017 Posted March 9, 2017 I've seen in alot of codes with "complex" math operations using that operator, mathemathically talking what it does exactly?
pa3ck Posted March 9, 2017 Posted March 9, 2017 That's modulus. It get's the remainder of 2 numbers that divide into each other. For example 5%2 will give you 1, because you can only divide 2 into 5 twice (2x2=4) and the remainder is 1. 6%3 = 0, because 2x3 = 6 7%3 = 1, because 2x3 = 6 and remainder is 1 etc. Most of the times I used it to check if a number is even like: local myNum = 11 if ( myNum % 2 == 0 ) then -- if you divide by 2 and no remainder, it's even print('even') else print('odd') end 1
ManeXi Posted March 9, 2017 Author Posted March 9, 2017 So if I get, it just gives the remainder of a division, nice to know.
Gordon_G Posted March 10, 2017 Posted March 10, 2017 (edited) One more information : In french we call this operation : Division euclidienne In english it's probably : Euclidean division Edited March 10, 2017 by Gordon_G
Moderators Citizen Posted March 11, 2017 Moderators Posted March 11, 2017 On 09/03/2017 at 18:45, ManeXi said: it just gives the remainder of a division Yes exactly. 22 hours ago, Gordon_G said: In french we call this operation : Division euclidienne Actually, no. We call this operator a "modulo" which is the remainder of a "Division euclidienne" as you said. You mixed "/" with "%" Quote 5 % 3 = 2 5 modulo 3 = 2 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now