@@ -174,17 +174,17 @@ std::string jkqtp_floattounitstr(double data, int past_comma, bool remove_trail0
174174 const double absData = fabs (data);
175175 int exponent = 0 ; // exponent in steps of 3: 0 -> no unit, +3 -> k, -3 -> m, etc.
176176 double scaled = absData;
177+ const double rel_tol = 1e-12 ;
177178
178179 // Scale down for large values (k, M, G, ...).
179- while (scaled >= 1000.0 && exponent < 30 ) {
180+ while (scaled >= ( 1000.0 -rel_tol) && exponent < 30 ) {
180181 scaled /= 1000.0 ;
181182 exponent += 3 ;
182183 }
183184
184185 // Scale up for small values (m, µ, n, ...).
185186 // Use a small tolerance to avoid misclassifying exact thresholds (1.0) due to
186187 // tiny floating-point round-off differences on some architectures (e.g. i386).
187- const double rel_tol = 1e-12 ;
188188 while (scaled > 0.0 && scaled < (1.0 - rel_tol) && exponent >= -27 ) {
189189 scaled *= 1000.0 ;
190190 exponent -= 3 ;
@@ -233,15 +233,15 @@ std::string jkqtp_floattolatexunitstr(double data, int past_comma, bool remove_t
233233 const double absData = fabs (data);
234234 int exponent = 0 ;
235235 double scaled = absData;
236- while (scaled >= 1000.0 && exponent < 30 ) {
236+ const double rel_tol = 1e-12 ;
237+ while (scaled >= (1000.0 -rel_tol) && exponent < 30 ) {
237238 scaled /= 1000.0 ;
238239 exponent += 3 ;
239240 }
240241
241242 // Scale up for small values (m, µ, n, ...).
242243 // Use a small tolerance to avoid misclassifying exact thresholds (1.0) due to
243244 // tiny floating-point round-off differences on some architectures (e.g. i386).
244- const double rel_tol = 1e-12 ;
245245 while (scaled > 0.0 && scaled < (1.0 - rel_tol) && exponent >= -27 ) {
246246 scaled *= 1000.0 ;
247247 exponent -= 3 ;
0 commit comments