How to calculate the Integer portion of a fraction using only +, -, &#x00F7;<!-- ÷ --> and *?

antennense

antennense

Answered question

2022-07-04

How to calculate the Integer portion of a fraction using only +, -, ÷ and *?
I made something in excel that calculates the days left until a given date, and from that how many weeks were left. I had it so that 9 days displayed as 1.2 using this formula:
( A B A B ) B 10 + A B
Where B is the "base" you are counting in and A is the number you are trying to count.
This all works and the question is purely for personal interest only.
So, Is there a way to calculate the Integer portion of a fraction only using the operators +, -, ÷ and *? Thanks In Advance

Answer & Explanation

Sophia Mcdowell

Sophia Mcdowell

Beginner2022-07-05Added 14 answers

You can take advantage of the fact that modulo is the same as the quotient operator for positive values and then sign correct the result. Not the most elegant solution but something like this should work.
A B = { | A | | A | % | B | | B | , for sgn(A)  = sgn(B) | A | | A | % | B | | B | 1 , for sgn(A)  sgn(B) }
where sgn is the signum function.

Do you have a similar question?

Recalculate according to your conditions!

Ask your question.
Get an expert answer.

Let our experts help you. Answer in as fast as 15 minutes.

Didn't find what you were looking for?