generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Modulus Function Help

Previous Thread :: Next Thread 
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
12 May 2015 08:36 AM
function Modulus(n1, n2)
local n1 = n1
local counter = 0
repeat
counter = counter + 1
n1 = n1 - n2
wait()
until n1 - n2 < 0
return n1, counter
end


So basically, I need help making the above support decimals and negatives. I also have a division function that relies heavily on the above:

function Divide(n1, n2)
local ans = ""
local rem, n2, nxt = n1, n2, nil
repeat
rem, nxt = Modulus(n1, n2)
ans = ans .. nxt
n1 = tonumber(tostring(rem) .. "0")
if not ans:find("%.") then
ans = ans .. "."
end
wait()
until rem == 0 or #ans == 18
return tonumber(ans)
end


So as much help as I can get would be appreciated.
Report Abuse
epicbreaker is not online. epicbreaker
Joined: 23 Apr 2011
Total Posts: 2791
12 May 2015 08:37 AM
WHY ARE YOU RECREATING THE WHEEL

kthx
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
12 May 2015 08:39 AM
I have my reasons. But those reasons do not matter for the above. I need help making the above support decimals and negatives.
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
12 May 2015 09:39 AM
Are you trying to recreate modulo?

local function Mod(Number, By)
local A = Number / By
return (A - math.floor(A)) * By
end
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
12 May 2015 09:44 AM
@Jarod I can't use /

If I use / that means Divide will have to rely on itself, and that just won't work.
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
12 May 2015 09:46 AM
Hmm. A simple search gives this as a first result:
homepage.cs.uiowa.edu/~jones/bcd/mod.shtml

This is another relevant result:
stackoverflow.com/questions/26047196
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
12 May 2015 09:49 AM
Jarod, my function works, I just need to add decimal and negative support. How do you suggest I do that?
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
12 May 2015 09:52 AM
I don't know, really. You could try something with math.floor. I need to go though, so I can't really help.
Not to mention I haven't really even read your script (I tried three times, but each time I forgot that I wanted to pay attention to it and got distracted)
Report Abuse
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
12 May 2015 09:52 AM
Multiply the number by 10 or something then use your function then divide it by the amount you multiplied it.


I hope I'm right...

Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
12 May 2015 09:55 AM
Division a / b could theoretically be expressed as a * b^-1

Thank reciprocals.
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
12 May 2015 09:56 AM
function Modulus(n1, n2)
local n1 = n1
local counter = 0
local neg = not (math.abs(n2) == n2)
repeat
counter = counter + 1
n1 = n1 - n2
wait()
until n1 - n2 < 0
return neg and -n1 or n1, counter
end


I think the above supports negatives. I might be wrong though. Would the above work if I start dividing negativesÉ
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
12 May 2015 10:00 AM
@eLunate

Sounds promising, but first I'd have to add decimal support to my Multiply and negative support to my Exponent LOL
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image