The definition of the floor function is clear and all, I just can't think of a recursive definition to find the floor of a non-negative real number.
2026-04-03 14:56:52.1775228212
On
On
What's a recursive algorithm for finding the floor of a non-negative real number?
889 Views Asked by Bumbble Comm https://math.techqa.club/user/bumbble-comm/detail At
3
There are 3 best solutions below
0
On
How about
$$ f(x)=\begin{cases}x, & x\in\mathbb{Z}\\f(x)-\frac1\pi|\sin(\pi f(x))|,&\text{else}\end{cases} $$
0
On
This would work, I think:
Define Floor(real R, integer I) as follows:
integer Floor(real R, integer I) {
//assumes that R >= 0
if R <= I
return I
else
return Floor(R, I+1)
}
Invoke the algorithm by calculating Floor(R, 0).
For large real numbers, it will take a loooooooong time to calculate it, and lots of stack space on your computer, but it will eventually hit the right integer, without fail.
(There are far better ways to calculate the floor than with a recursive function in practice.)
$f(x)$ = if $x<1$ return $0,$ else return $f(x-1)+1.$
For large $x$ this may be subject to rounding errrors, depending on how numbers are stored/ manipulated.