diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2017-07-31 16:40:26 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2017-07-31 16:43:14 +0300 |
commit | b6cb7b2c92bfa3fa111e4e363f723baadc56ed3c (patch) | |
tree | 1e65eb9ee25dd09193edb004c00ac12eddde4a4e /source/blender/blenkernel/intern/unit.c | |
parent | 09eac0159db81a07268a1246ed88fd9257a7a04f (diff) |
Fix two issues with recent changes to number display while editing them.
* Numbers with units (especially, angles) where not handled correctly
regarding number of significant digits (spotted by @brecht in T52222
comment, thanks).
* Zero value has no valid log, need to take that into account!
Diffstat (limited to 'source/blender/blenkernel/intern/unit.c')
-rw-r--r-- | source/blender/blenkernel/intern/unit.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/unit.c b/source/blender/blenkernel/intern/unit.c index c0a373395dc..f97b89f1fd5 100644 --- a/source/blender/blenkernel/intern/unit.c +++ b/source/blender/blenkernel/intern/unit.c @@ -372,6 +372,13 @@ static size_t unit_as_string(char *str, int len_max, double value, int prec, con value_conv = value / unit->scalar; + /* Adjust precision to expected number of significant digits. + * Note that here, we shall not have to worry about very big/small numbers, units are expected to replace + * 'scientific notation' in those cases. */ + const int l10 = (value_conv == 0.0) ? 0 : (int)log10(fabs(value_conv)); + prec -= l10 + (int)(l10 < 0); + CLAMP(prec, 0, 6); + /* Convert to a string */ len = BLI_snprintf_rlen(str, len_max, "%.*f", prec, value_conv); |