int, rest = restDivision(50, 8) -- int --> 6 -- rest -- > 0.25
Edited by Sewbacca, 04 April 2016 - 06:14 PM.
Posted 04 April 2016 - 05:42 PM
int, rest = restDivision(50, 8) -- int --> 6 -- rest -- > 0.25
Edited by Sewbacca, 04 April 2016 - 06:14 PM.
Posted 04 April 2016 - 05:49 PM
local function intDiv(a, B)/> local div = a / b local round = div < 0 and math.ceil(div) or math.floor(div) return round, div - round end intDiv(50, 8) -- 6, 0.25 intDiv(-50, 8) -- -6, -0.25 -- You can always do math.abs on the rest to get the positive version
Edited by SquidDev, 04 April 2016 - 05:50 PM.
Posted 04 April 2016 - 05:57 PM
Posted 05 April 2016 - 12:03 AM
local function restDivision(numerator,divisor) --#Grab just the pure division, since that's going to be int plus rest local int = numerator/divisor --#Grab our decimal, this is your rest local decimal = int % 1 --#Remove the decimal from int int = int - decimal --#return return int,decimal end
Posted 05 April 2016 - 12:15 AM
Posted 05 April 2016 - 12:44 AM
local function restDivision(numerator,divisor) --#Grab just the pure division, since that's going to be int plus rest local int = numerator/divisor --#Grab our decimal, this is your rest local decimal = int % 1 --#Remove the decimal from int --#the and or parts is lua ternary. --#Basically if int > 0 then int = int - decimal --#else int = int + decimal int = int > 0 and int - decimal or int + decimal --#return return int,decimal end
Posted 05 April 2016 - 12:56 AM
print(restDivision(-50, 8)) --> ???
Posted 05 April 2016 - 02:28 AM
local function restDivision(numerator,divisor) --#Grab just the pure division, since that's going to be int plus rest local int = numerator/divisor --#Grab our decimal, this is your rest --#Woo, doing the ternary HERE local decimal = int % (int > 0 and 1 or -1) int = int - decimal --#return return int,decimal end
Edited by Dragon53535, 05 April 2016 - 02:30 AM.
0 members, 2 guests, 0 anonymous users