How to seperate fractional and decimal part in a real number

I need formula for Modulo, or Fraction

I was wondering, is this even possible? I know there are lot's of solutions for this problem in computer science but is there a solution for this problem in arithmetics?

For example, if it is divisible by two, we can use: X mod 2 = (1+(-1)^(x-1))/2

please help me, or If it does not exist then tell me

Why am I looking for Formula for Modulo

Because (x mod 1) gives me the decimal part of a real number X, Or by using Fraction equation if it exists

Another example , For integers

But I am looking for real numbers formula

I'm not sure, but in terms of integer values for modulo 2 I have another way to do it.

x mod 2=1/2+cos(pi*x)/2

For even numbers: cos(pi*x)=1...so, 1/2+1/2=1

For odd numbers: cos(pi*x)=(-1)...so, 1/2+(-1/2)=0

Thank you very much Phinehas

I said in the first post: "How to seperate fractional and decimal part in a real number", So, Through your idea:

X=real number

For odd numbers: Decimal(X)=1-ACos(Cos(X*PI))/(PI)

For even numbers: Decimal(X)= ACos(Cos(X*PI))/(PI)

And :

Fraction=X-Decimal=Int(X)

Any idea for a general function?

The separating decimals from the whole is the easiest one. For positive numbers, the whole is floor(x) while the decimal is x-floor(x). For negative numbers, just change floor(x) with ceil(x).

For x mod y, it's a bit harder but still no problem. x mod y is just the remainder after you divide x by y, so the first step is to just divide x by y. Then keep the decimals using the method described above and multiply by y again. In short,

x mod y = y(x/y - floor(x/y)) {x > 0}

x mod y = y(x/y - ceil(x/y)) {x <= 0}

One problem. The negative formula doesn't work. That formula earlier for decimals only got the decimals and kept the sign. Modulo doesn't care about signs, so we can actually throw out the negatives definition.

Just a little cleaning up now. That y(x/y) is one hell of a way to write x. So let's distribute to keep that x and cancel out the y's.

x mod y = x - y*floor(x/y)

Really simple, isn't it?