10 if (!std::isfinite(value) || value == 0.0)
return value;
11 const double magnitude = std::floor(std::log10(std::abs(value)));
12 const double scale = std::pow(10.0, 9.0 - magnitude);
13 const double rounded = std::floor(std::abs(value) * scale + 0.5) / scale;
14 return value < 0.0 ? -rounded : rounded;
18 if (!(step > 0.0) || !std::isfinite(qty) || qty <= 0.0)
return qty;
19 double floored = std::floor(qty / step) * step;
21 const double cent_candidate = std::floor(qty * 100.0) * step;
22 if (cent_candidate > floored && cent_candidate <= qty)
23 floored = cent_candidate;
25 return floored < qty ? floored : qty;