c++ – How to prevent float overflow and underflow?
vector3d scale_vector(const vector3d& v, const float& scaler)
{
vector3d new_vector;
new_vector.x = v.x * scaler;
new_vector.y = v.y * scaler;
new_vector.z = v.z * scaler;
return new_vector;
}
float calculate_dustance(const point3d& point_0, const point3d& point_1)
{
return sqrtf((point_0.x - point_1.x) * (point_0.x - point_1.x)
+ (point_0.y - point_1.y) * (point_0.y - point_1.y)
+ (point_0.z - point_1.z) * (point_0.z - point_1.z));
}
How to prevent overflow in these kind functions? I saw some posts about int-overflow but no one mentioned float.
Read more here: Source link