1

I want to extract the integer part of number.

For example, I have the number 2.754 and the expected result would be 2.

Can i do it in a mathematical way?

Dan Dan
  • 135

2 Answers2

3

In a mathematical way is a pretty vague term.

Consider the tangent function $\tan(x)$ and the usual branch of its inverse, $\arctan(x)$, from $\mathbb R$ to $(-\pi/2,\pi/2)$.

Then with appropriate scalings and shiftings

$$f(x)=\frac1\pi\arctan\left(\tan\left(\pi\left(x+\frac12\right)\right)\right)+\frac12$$

is a sawtooth signal of period $1$, i.e. the fractional part of $x$.

enter image description here

Then $x-f(x)$ is the integer part.

This definition doesn't work for integers though :(

  • what if you take limit x tends to z of your final function, to get the integer part of the real number z? That would be a mathematical expression that doesn't resort to using the convenience of the computer-programming like function 'floor'. i'm really impressed by this, I was trying stuff with arcsin etc but it only worked for some numbers – Cato Nov 23 '16 at 16:38
  • @Cato: $\sin/\arcsin$ and $\cos/\arccos$ combinations will end-up in a continuous function, so they are forever unable to extract the fractional part. Of course you can use the left-side limit of the function at integer numbers, but that looks like an "if" test requiring... the floor function. –  Nov 23 '16 at 17:23
  • if use int detection https://math.stackexchange.com/questions/339510/mathematical-way-of-determining-whether-a-number-is-an-integer/1598552#1598552 and 'if' function https://youtu.be/KAdKCgBGK0k?list=PLnI9xbPdZUAmUL8htSl6vToPQRRN3hhFp&t=313 then may build for integers – Serg Kryvonos Feb 27 '19 at 21:31
1

Yes, this is the floor function, $f(x)=\lfloor x\rfloor$. For a real number $a$, the integer part of $a$ is denoted $\lfloor a\rfloor$ (i.e. the floor of $a$).

Edit: Note that this notation is given as \lfloor x \rfloor, where \lfloor is the left side of the floor (i.e. \lfloor=$\lfloor$) and \rfloor is the right side of the floor (i.e. \rfloor=$\rfloor$).

Dave
  • 13,568