now i have a segment of code running online:
def div1(val, min, max, period):
der = (max - min) / period # 0.005
return val // der # 41
# call div1
div1(0.21, 0, 1, 200)
when i call the function with div1(0.21, 0, 1, 200)
, i get the result of 41.
Now, i want to transform it to C++ language.
But in C++, i get 42 instead of 41.
int Box(double val, double min, double max, double period) {
double der = (max - min) / period; // 0.005
int final_val = floor(val / der); // 42
return final_val;
}
Box(val, 0, 1, 200) // get 42
any thing wrong with my code? and how to fix it if i want to get the same result in C++?
ps: the code of Python CAN NOT be modified...