[Bf-blender-cvs] [075def8fbda] master: Util function to determine number of digits from an integer

Dalai Felinto noreply at git.blender.org
Fri Jan 19 20:01:30 CET 2018


Commit: 075def8fbda709e9db9086e9f2800a56103eb35d
Author: Dalai Felinto
Date:   Fri Jan 19 16:52:59 2018 -0200
Branches: master
https://developer.blender.org/rB075def8fbda709e9db9086e9f2800a56103eb35d

Util function to determine number of digits from an integer

===================================================================

M	source/blender/blenkernel/intern/image.c
M	source/blender/blenlib/intern/math_base_inline.c
M	source/blender/editors/space_text/text_draw.c

===================================================================

diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index e3e403251e1..bd2373a59d5 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -1695,7 +1695,7 @@ static void stampdata(Scene *scene, Object *camera, StampData *stamp_data, int d
 		int digits = 1;
 
 		if (scene->r.efra > 9)
-			digits = 1 + (int) log10(scene->r.efra);
+			digits = integer_digits_i(scene->r.efra);
 
 		BLI_snprintf(fmtstr, sizeof(fmtstr), do_prefix ? "Frame %%0%di" : "%%0%di", digits);
 		BLI_snprintf(stamp_data->frame, sizeof(stamp_data->frame), fmtstr, scene->r.cfra);
diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c
index 9202efce7b4..a0c13e14e72 100644
--- a/source/blender/blenlib/intern/math_base_inline.c
+++ b/source/blender/blenlib/intern/math_base_inline.c
@@ -397,6 +397,10 @@ MINLINE int integer_digits_d(const double d)
 	return (d == 0.0) ? 0 : (int)floor(log10(fabs(d))) + 1;
 }
 
+MINLINE int integer_digits_i(const int i)
+{
+	return (int)log10(i) + 1;
+}
 
 /* Internal helpers for SSE2 implementation.
  *
diff --git a/source/blender/editors/space_text/text_draw.c b/source/blender/editors/space_text/text_draw.c
index 70b5feac280..4eb66811c7d 100644
--- a/source/blender/editors/space_text/text_draw.c
+++ b/source/blender/editors/space_text/text_draw.c
@@ -594,7 +594,7 @@ static void text_update_drawcache(SpaceText *st, ARegion *ar)
 			drawcache->total_lines = 0;
 
 			if (st->showlinenrs)
-				st->linenrs_tot = (int)floor(log10((float)nlines)) + 1;
+				st->linenrs_tot = integer_digits_i(nlines);
 
 			while (line) {
 				if (drawcache->valid_head) { /* we're inside valid head lines */
@@ -628,7 +628,7 @@ static void text_update_drawcache(SpaceText *st, ARegion *ar)
 			nlines = BLI_listbase_count(&txt->lines);
 
 			if (st->showlinenrs)
-				st->linenrs_tot = (int)floor(log10((float)nlines)) + 1;
+				st->linenrs_tot = integer_digits_i(nlines);
 		}
 
 		drawcache->total_lines = nlines;



More information about the Bf-blender-cvs mailing list