Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

floor()/int() function implementaton

Does anyone have an idea how is the method/function Int() or floor() implemented? What I am looking for a respective implementation as the following is for abs() function.

Int Abs (float x){
  if x > 0 
      return x;
   else
      return -x
}

I am struggling to find a solution for it without using the modulus operator.

like image 395
Olga Avatar asked Feb 25 '11 21:02

Olga


1 Answers

Seems to me like

floor(n) = n - (n % 1)

should do the trick.

like image 134
TheJubilex Avatar answered Nov 10 '22 00:11

TheJubilex