//this is all the stuff i didn't make but is very useful to me with full credit to original authors/sources

//https://wiki.srb2.org/wiki/User:Clairebun/Sandbox/Common_Lua_Functions#L_TurnAngle
local function EaseAngle(sta,en,rate)
	return sta + FixedMul(en-sta,rate)
end

//https://wiki.srb2.org/wiki/User:Clairebun/Sandbox/Common_Lua_Functions#L_DecimalFixed
local function DecimalToFixed(decimalAsString)
	if (BonkerBox_G.StringEmptyOrNil(decimalAsString, false)==true)
		return 0
	end
	
	local dec_offset = string.find(decimalAsString,'%.')
	
	if (dec_offset==nil)
		return (tonumber(decimalAsString) or 0)*FRACUNIT
	end
	
	local wholestr = string.sub(decimalAsString,0,dec_offset-1)
	local decstr = string.sub(decimalAsString,dec_offset+1)
	
	local whole = tonumber(wholestr) or 0
	local decimal = tonumber(decstr) or 0
	
	if(decimal==0)
		decstr = "0"
	end
	
	whole = $ * FRACUNIT
	local dec_len = string.len(decstr)
	decimal = $ * FRACUNIT / (10^dec_len)
	return whole + decimal
end

//https://wiki.srb2.org/wiki/User:Clairebun/Sandbox/Common_Lua_Functions#L_FixedDecimal
local function FixedToDecimal(val,places)
	if (BonkerBox_G.IsNumber(val)~=true)
		return nil
	end
	
	if(BonkerBox_G.IsNumber(places)~=true)
		places=3
	end
	
	if(val==0)
		return '0'
	end

	local polarity = abs(val)/val
	local str_polarity = (polarity < 0) and '-' or ''
	local str_whole = tostring(abs(val/FRACUNIT))
	
	if (places<=0)
		return str_polarity..str_whole
	end
	
	local decimal = val%FRACUNIT
	decimal = FRACUNIT + $
	decimal = FixedMul($,FRACUNIT*10^places)
	decimal = $>>FRACBITS
	local str_decimal = string.sub(decimal,2)
	return str_polarity..str_whole..'.'..str_decimal
end

local external = {}
external.EaseAngle = EaseAngle
external.DecimalToFixed = DecimalToFixed
external.FixedToDecimal = FixedToDecimal
rawset(_G,"BonkerBox_E",external)