Squirrel built-in math functions (handmade)

Started by (vG)DesTroYeR^, Today at 02:24 PM

Previous topic - Next topic

(vG)DesTroYeR^

function ToLower(num) { // (Floor)
local fltdot = ".";
local numstr = num+"";
local checkflt = split(numstr, fltdot);
if(checkflt.len() > 2) return print("Wrong float value detected.");
if(checkflt.len() == 2){
local w = checkflt[0].tointeger(); \\ before the dot. like 34(.)5 - it will return 34
return w;
}
return print("Invalid input (ToLower)");
}

function ToGreater(num) { // (Ceil)
local fltdot = ".";
local numstr = num+"";
local checkflt = split(numstr, fltdot);
if(checkflt.len() > 2)return print("Invalid input - ToGreater()"); // must be 1 dot.
if(checkflt.len() <= 1)return print("Invalid input - ToGreater()"); // no integers. or (34.) so the dot in 34 is not a valid input
local floats = "0."+checkflt[1];
local integers = checkflt[0];
if (checkflt[1].tointeger() == 0) return integers.tointeger(); // if 34.0 return 34
local subTracT =  floats.tofloat() - 1;
local subT = abs(subTracT); // (+)

local result = num + subT; // 34.3 + 0.7 = 35
return result;
}

idk whats the purpose of these codes, but i like to know how built-in math funcs work - so are these funcs used above work correctly?