mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-26 10:51:54 -04:00
Avoid floating point underflow in thermal computation
This commit is contained in:
parent
7ac780c0ea
commit
b017cd53d6
1 changed files with 8 additions and 1 deletions
|
|
@ -8,6 +8,7 @@
|
|||
#include "io.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
|
||||
struct snapraid_thermal* thermal_alloc(uint64_t dev, const char* name)
|
||||
{
|
||||
|
|
@ -103,7 +104,13 @@ struct snapraid_thermal_params fit_thermal_model(const struct snapraid_thermal_p
|
|||
}
|
||||
|
||||
model.rmse = sqrt(sum_squared_residuals / n_points);
|
||||
model.r_squared = 1.0 - (sum_squared_residuals / sum_total);
|
||||
|
||||
/* avoid sum_total underflow and division by zero */
|
||||
if (sum_total > FLT_EPSILON) {
|
||||
model.r_squared = 1.0 - (sum_squared_residuals / sum_total);
|
||||
} else {
|
||||
model.r_squared = 1.0;
|
||||
}
|
||||
|
||||
return model;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue