# Exercise Corrige Redressement Simple Alternance 40.pdf ((HOT)) Exercise Corrige Redressement Simple Alternance 40.pdf

A:

Regarding my comment :
You can avoid calculating in the beginning of each loop the floating point error by calculating only once the total number of loops (that’s the *floorf() call) and apply it into the loop like below.
Round = floorf(loop_start/loops_per_pendulum)
mid = (loops_per_pendulum-1)*Round+roundf(loop_start/loops_per_pendulum-1)

Like this your function will compute everything once and give the error correct, the compiler will calculate only the actual number of loops.
For example, with your input values :

rounds_per_pendulum = 10
loop_start = 1.900573680058719e+07
loops_per_pendulum = loop_start / rounds_per_pendulum = 0.677920133131623e+07

We get the following values :
rounds_per_pendulum = 10
loop_start = 1.900573680058719e+07
loops_per_pendulum = 0.677920133131623e+07

Since we have 10 rounds_per_pendulum and 0.677920133131623e+07 loops_per_pendulum we get :
mid = (0.677920133131623e+07 – 1)*(10 – 1) + roundf(1.900573680058719e+07 / 0.677920133131623e+07 – 1)

mid = 1.171258874129984e+07 + roundf(0.01903807472447241 – 1) = 1318160195472658

This is what happens if you put rounds_per_pendulum = 20 :
rounds_per_pendulum = 20
loop_start = 1.890978817506525e+08
loops_per_pendulum = loop_start / rounds_per_pendulum = 0.6870814267231904e+07

rounds_per_pendulum = 20
loop_start = 1.890978817506525e+08
loops_per_pendulum = 0.6870814

0644bf28c6

#### Latest News 20 Jun 21

• 1 Apr, 2023
• 1 Apr, 2023
• 31 Mar, 2023

#### Latest News 20 Jun 21

• 1 Apr, 2023
• 1 Apr, 2023
• 31 Mar, 2023

### Contact Info

Narayani Building,