I want to know what does this formula do with the integer $x$
$$\text{frac}(x) = x - \lfloor {x}\rfloor ,\ x >= 0$$
I've searched and found that this is called finding the fraction part of $x$
Can anyone explain it for me?
I want to know what does this formula do with the integer $x$
$$\text{frac}(x) = x - \lfloor {x}\rfloor ,\ x >= 0$$
I've searched and found that this is called finding the fraction part of $x$
Can anyone explain it for me?
On
If I understand correctly then you mean: f(x)=abs(x - [x]), when [x] is the floor function of x. floor function of x: max{n, n is integer and n<=x}
for example f(-5.372)= -5.372-floor(-5.372)=abs(-5.372-(-5))=0.372
it could be without abs.
The function f(x) returns the part after the decimal point for the decimal representation of x.
On
The 'floor' function $(\lfloor \cdot \rfloor)$, returns the largest integer value which is less than (or equal to) the argument which was provided.
For example: $$\lfloor 4 \rfloor = \lfloor 4.5 \rfloor = 4$$ The function you created 'frac' is the difference of the argument, and it's integer part, so that you are basically returning the fractional remainder
First, look at $$\lfloor {x}\rfloor $$ which finds the largest integer less than or equal to $x$. Some examples:
\begin{align} x && \lfloor {x}\rfloor\\ 3.2 && 3.0\\ 1.999 && 1\\ 0.5 && 0.0 \\ 4.0 && 4.0 \end{align}
Now let's subtract $\lfloor {x}\rfloor$ from $x$: \begin{align} x && \lfloor {x}\rfloor && x - \lfloor {x}\rfloor\\ 3.2 && 3.0 && 0.2\\ 1.999 && 1 && 0.999\\ 0.5 && 0.0 && 0.5\\ 4.0 && 4.0 && 0.0 \end{align}
In short: for positive numbers, this expression is "the stuff to the right of the decimal point."
Extra credit: You might ask yourself why this doesn't work for negative numbers.