In this exercise, you'll be writing code to help a freelancer communicate with a project manager. Your task is to provide a few utilities to quickly calculate daily and monthly rates, optionally with a given discount.
We first establish a few rules between the freelancer and the project manager:
Sometimes, the freelancer is offering to apply a discount on their daily rate (for example for their most loyal customers or not-for-profit customers).
Discounts are modeled as fractional numbers representing percentages, for example, 25.0 (25%).
These are the suffixes to floating-point instructions:
| Suffix | Operand size |
|---|---|
ss | 32-bit |
sd | 64-bit |
These are some of the instructions mentioned in this concept:
| Instruction | Description |
|---|---|
| movss/movsd a, b | copies b to a |
| addss/addsd a, b | a = a + b |
| subss/subsd a, b | a = a - b |
| mulss/mulsd a, b | a = a * b |
| divss/divsd a, b | a = a / b |
| cvtsi2ss/cvtsi2sd a, b | converts integer b to floating-point a |
| roundss/roundsd a, b, c | rounds floating-point b according to c and stores in a |
| cvtss2si/cvtsd2si a, b | converts floating-point b to integer a |
| comiss/comisd a, b | makes a comparison between a and b, exception if NaN |
| ucomiss/ucomisd a, b | makes a comparison between a and b, sets PF if NaN |
These are the rounding control numbers in roundss and roundsd:
| Number | Mode |
|---|---|
| 0 | Nearest |
| 1 | Floor (down) |
| 2 | Ceil (up) |
| 3 | Truncate |
Implement a function called daily_rate to calculate the daily rate given as parameter an hourly rate, as a 64-bit floating-point number.
The contract defines that a day has 8 billable hours.
daily_rate(60)
// => 480.0The returned daily rate should be a 64-bit floating-point number.
Implement a function apply_discount to calculate the price after a discount.
It should accept two parameters: the original price and the discount rate in percent, both as a 64-bit floating-point number.
apply_discount(150.0, 10.0)
// => 135.0The returned value should always be a 64-bit floating-point number.
Implement a monthly_rate function to calculate the discounted monthly rate.
It takes two parameters, an hourly rate and the discount in percent, both as a 64-bit floating-point number.
monthly_rate(77.0, 10.5)
// => 12130The returned monthly rate should be rounded up (take the ceiling) to the nearest 64-bit integer.
Implement a function days_in_budget that takes as parameters:
This function should return the number of complete days of work the budget covers.
days_in_budget(20000, 80, 11.0)
// => 35The returned number of days should be rounded down (take the floor) to the nearest 32-bit integer.
In this exercise, you'll be writing code to help a freelancer communicate with a project manager. Your task is to provide a few utilities to quickly calculate daily and monthly rates, optionally with a given discount.
We first establish a few rules between the freelancer and the project manager:
Sometimes, the freelancer is offering to apply a discount on their daily rate (for example for their most loyal customers or not-for-profit customers).
Discounts are modeled as fractional numbers representing percentages, for example, 25.0 (25%).
These are the suffixes to floating-point instructions:
| Suffix | Operand size |
|---|---|
ss | 32-bit |
sd | 64-bit |
These are some of the instructions mentioned in this concept:
| Instruction | Description |
|---|---|
| movss/movsd a, b | copies b to a |
| addss/addsd a, b | a = a + b |
| subss/subsd a, b | a = a - b |
| mulss/mulsd a, b | a = a * b |
| divss/divsd a, b | a = a / b |
| cvtsi2ss/cvtsi2sd a, b | converts integer b to floating-point a |
| roundss/roundsd a, b, c | rounds floating-point b according to c and stores in a |
| cvtss2si/cvtsd2si a, b | converts floating-point b to integer a |
| comiss/comisd a, b | makes a comparison between a and b, exception if NaN |
| ucomiss/ucomisd a, b | makes a comparison between a and b, sets PF if NaN |
These are the rounding control numbers in roundss and roundsd:
| Number | Mode |
|---|---|
| 0 | Nearest |
| 1 | Floor (down) |
| 2 | Ceil (up) |
| 3 | Truncate |
Implement a function called daily_rate to calculate the daily rate given as parameter an hourly rate, as a 64-bit floating-point number.
The contract defines that a day has 8 billable hours.
daily_rate(60)
// => 480.0The returned daily rate should be a 64-bit floating-point number.
Implement a function apply_discount to calculate the price after a discount.
It should accept two parameters: the original price and the discount rate in percent, both as a 64-bit floating-point number.
apply_discount(150.0, 10.0)
// => 135.0The returned value should always be a 64-bit floating-point number.
Implement a monthly_rate function to calculate the discounted monthly rate.
It takes two parameters, an hourly rate and the discount in percent, both as a 64-bit floating-point number.
monthly_rate(77.0, 10.5)
// => 12130The returned monthly rate should be rounded up (take the ceiling) to the nearest 64-bit integer.
Implement a function days_in_budget that takes as parameters:
This function should return the number of complete days of work the budget covers.
days_in_budget(20000, 80, 11.0)
// => 35The returned number of days should be rounded down (take the floor) to the nearest 32-bit integer.