註解
解釋部分程式
float binary_approx(float target_value, float leftbound, float rightbound, float epoch) {
float guess_value;
// try to guess a value for epoch times
float guess_value;
for (int i = 0; i < epoch; i++) {
// choosing the guess value to the average of the bounds
guess_value = (leftbound + rightbound) / 2.0;
// if guessed lower than target, set leftbound to guess value
if (guess_value < target_value) {
leftbound = guess_value;
}
// if guessed higher than target, set rightbound to guess value
else if (guess_value > target_value) {
rightbound = guess_value;
}
else {
return guess_value;
}
}
return guess_value;
}Documentation
Documenting functions
Documenting classes
Last updated