Videos
What is the domain of the floor and ceiling function?
The domain of the floor and ceiling function is the set of all real numbers. The image, in turn, is the set of integers.
How do I calculate the ceiling of a number?
To determine the ceiling of a number:
- If your number is an integer, then the ceiling is equal to this number. You're done!
- Otherwise, write down the integers that are greater than your number.
- Pick the smallest of the integers you've written down.
- That's it! You've found the ceiling of your number.
How do I calculate the floor of a number?
To determine the floor of a number:
- If your number is an integer, it is equal to its floor. In other words, you're done!
- If you're dealing with a non-integer, then write down the integers that are smaller than your number.
- Pick the greatest among the integers you've found in the previous step.
- That's it! You've calculated the floor of your number.
Hi all.
Iโve got several programmable AOS (Texas Instruments) and RPN (Hewlett Packard) calculators.
How would I write floor & ceiling functions for both AOS & RPN calcs?
Simply put it's two ways of thinking of rounding off a number. Ceiling rounds up to nearest integer. Floor rounds down to nearest integer. If the number is an integer, nothing happens.
It's easy to think about floor and ceil from the perspective of the number line.
Let's say you have some decimal number, $2.31$ (I'm going to be using this number as an example throughout my answer)
$\hskip2in$
So, as you can see, the functions just return the nearest integer values.
floor returns the nearest lowest integer and ceil returns the nearest highest integer.
All real numbers are made of a characteristic (an integer part) and mantissa (a fractional part) $$\text{Number} = \text{Characteristic} + \text{Mantissa}$$ $$2.31 = 2 + 0.31$$
When floor a number, you can think of it as replacing the Mantissa with $0$ $$\lfloor 2.31 \rfloor = 2 + 0 = 2$$
and ceil can be thought of as replacing the mantissa with $1$. $$\lceil 2.31 \rceil = 2 + 1 = 3$$
That's not a very popular way of thinking about it but it was the way I thought about it when I first started using it in programming.
Remember, the number remains the same when it is an integer. ie, floor($3$) $=$ ceil($3$) $= 3$
Let's now look at the proper definitions along with the graphs for them.
Floor Function: Returns the greatest integer that is less than or equal to $x$
$\hskip2in$
Ceiling Function: Returns the least integer that is greater than or equal to $x$
$\hskip2in$
Don't let the infinite staircase scare you. It's much more simpler than it seems. Those "line-segments" that you see are actually called piecewise-step functions.
Simply, the black dot represents 'including this number' and the white represents 'excluding this number'. Meaning that each segment actually is from x to all numbers less than x+1.
Let's look at 2.31 and how it would look on both the graphs at once.
You can see that the line $x=2.31$ hits the floor function at the "line-piece" for $2$
and hits the ceiling function at $3$ You can replace $\lfloor x \rfloor$ with $x - \theta$, where $\theta \in [0,1)$ is some unknown quantity. Similarly, $\lceil x \rceil = x + \theta$ (a different $\theta$ within the same range).
Another helpful identity is $\lfloor x \rfloor + n = \lfloor x + n \rfloor$ for any integer $n$.
Your final expression gives you the number you want.
According to your blog post, you're looking for the smallest integer $n$ (i.e., the "first Fibonacci number with 1000 digits") that satisfies $$G(n) = \left\lfloor n \log \varphi - \frac{\log 5}{2} \right\rfloor + 1.$$ There may, of course, be more than one integer $n$ for which this is true.
By definition of the floor function, the values of $n$ that satisfy this are the values that satisfy $$G(n) - 1 \leq n \log \varphi - \frac{\log 5}{2} < G(n),$$ which, since $\log \phi > 0$, are the values that satisfy $$\frac{G(n) + \frac{\log 5}{2}}{\log \varphi} - \frac{1}{\log \varphi} \leq n < \frac{G(n) + \frac{\log 5}{2}}{\log \varphi}.$$
Since $\frac{1}{\log \varphi} \approx 4.78$, there are either four or five integers in this interval. But the smallest one is obtained by taking the ceiling of the lower endpoint of the interval; i.e., $$\left\lceil\frac{G(n) + \frac{\log 5}{2} - 1}{\log \varphi}\right\rceil.$$
Incidentally, this argument also apparently shows that there are either four or five Fibonacci numbers that have a given number of digits. (Except in the single-digit case, where there are six (not counting 0). But your formula for $G(n)$ doesn't hold when $n=1$, so we shouldn't expect this calculation to be true in the single-digit case anyway.)