Greatest Integer Function Problem

  • Thread starter Lobdell
  • Start date
I just need a push in the right direction for this one.
The problem is: A phone company charges this amount for the first minute and that amount for each additional minute. If someone talks for 3.1 minutes, they are charged for 4 minutes. Make a formula, blah blah blah...
Anyway I'm having trouble with making the equation work for both of these situations: when x is an integer, and when x is not an integer.
I already thought about int(x-.1) but then x could be .01, and it wouldn't be correct.

Any help is appreciated.


Science Advisor
Homework Helper
You're trying to make a "round up" function. Since you're allowed to use the floor ("round down") function, consider this:

int(x)=-int(-x), x is an integer
int(x)=1-int(-x), otherwise


Science Advisor
All you need is a + b ceil(x-1), where a is the cost for the first minute and b is the cost of each additional minute.

Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving

Hot Threads