Index: include/config_win.h
===================================================================
--- include/config_win.h	(revision 59246)
+++ include/config_win.h	(working copy)
@@ -308,6 +308,7 @@
 #define fork() -1
 #define getprogname() _pgmptr
 #define rint(_X) (floor((_X) + 0.5))
+#define lrint(_X) (long int)(floor((_X) + 0.5))
 #define sleep(_SECONDS) (Sleep(1000 * (_SECONDS)))
 
 #ifndef __cplusplus
Index: include/icv.h
===================================================================
--- include/icv.h	(revision 59246)
+++ include/icv.h	(working copy)
@@ -149,7 +149,7 @@
  * extensions
  * @return File Format
  */
-ICV_EXPORT extern int icv_guess_file_format(const char *filename, char *trimmedname);
+ICV_EXPORT extern ICV_IMAGE_FORMAT icv_guess_file_format(const char *filename, char *trimmedname);
 
 /**
  * This function allocates memory for an image and returns the
Index: include/vmath.h
===================================================================
--- include/vmath.h	(revision 59246)
+++ include/vmath.h	(working copy)
@@ -1353,7 +1353,7 @@
  * replaced universally with fastf_t's since their epsilon is
  * considerably less than that of a double.
  */
-#define INTCLAMP(_a) (NEAR_EQUAL((_a), rint(_a), VUNITIZE_TOL) ? (double)(long)rint(_a) : (_a))
+#define INTCLAMP(_a) (NEAR_EQUAL((_a), rint(_a), VUNITIZE_TOL) ? rint(_a) : (_a))
 
 /** @brief integer clamped versions of the previous arg macros. */
 #define V2INTCLAMPARGS(a) INTCLAMP((a)[X]), INTCLAMP((a)[Y])
Index: misc/CMake/BRLCAD_CompilerFlags.cmake
===================================================================
--- misc/CMake/BRLCAD_CompilerFlags.cmake	(revision 59246)
+++ misc/CMake/BRLCAD_CompilerFlags.cmake	(working copy)
@@ -103,6 +103,8 @@
   CHECK_C_FLAG(Wall)
   CHECK_CXX_FLAG(Wall)
 
+  CHECK_C_FLAG(Wbad-function-cast)
+
   CHECK_C_FLAG(Wextra)
   CHECK_CXX_FLAG(Wextra)
 
Index: misc/CMake/test_srcs/builddelta_end.c.in
===================================================================
--- misc/CMake/test_srcs/builddelta_end.c.in	(revision 59246)
+++ misc/CMake/test_srcs/builddelta_end.c.in	(working copy)
@@ -1,7 +1,6 @@
 #include <time.h>
 #include <stdio.h>
 
-
 void
 printtime(int tdiff)
 {
@@ -84,7 +83,9 @@
 
   printf("Elapsed compilation time: ");
 
+#pragma GCC diagnostic ignored "-Wbad-function-cast"
   tdiff = (int)difftime(te, ts);
+#pragma GCC diagnostic pop
 
   printtime(tdiff);
 
@@ -96,7 +97,9 @@
   fclose(infp);
 
   ts = mktime(&starttime);
+#pragma GCC diagnostic ignored "-Wbad-function-cast"
   tdiff = (int)difftime(te, ts);
+#pragma GCC diagnostic pop
   printtime(tdiff);
   printf("\n---\n");
 
Index: src/conv/dem-g.c
===================================================================
--- src/conv/dem-g.c	(revision 59246)
+++ src/conv/dem-g.c	(working copy)
@@ -169,7 +169,7 @@
 	unsigned char highbyte = '\0';
 	unsigned char lowbyte = '\0';
 
-	highbyte = (unsigned char)floor(in_value / 256);
+	highbyte = (unsigned char)lrint(floor(in_value / 256));
 	lowbyte = (unsigned char)(in_value - (highbyte * 256));
 	out_string[0] = highbyte;
 	out_string[1] = lowbyte;
@@ -1431,7 +1431,7 @@
 		    curr_elevation = 0;
 		}
 
-		if (output_elevation((long int)round_closest(curr_elevation * raw_dem_2_raw_dsp_scale_factor), fp2) == BRLCAD_ERROR) {
+		if (output_elevation(lrint(round_closest(curr_elevation * raw_dem_2_raw_dsp_scale_factor)), fp2) == BRLCAD_ERROR) {
 		    bu_log("Function 'output_elevation' failed on 'b' record# '%ld', record elevation# '%ld', dem elevation# '%ld', raw elevation value '%ld'.\n", curr_b_record, elevation_number_in_curr_b_record, elevation_number, curr_elevation);
 		    fclose(fp);
 		    fclose(fp2);
@@ -1438,7 +1438,7 @@
 		    return BRLCAD_ERROR;
 		}
 	    }
-	    additional_1024char_chunks = (long int)ceil((tot_elevations_in_curr_b_record - 146.0) / 170.0);
+	    additional_1024char_chunks = lrint(ceil((tot_elevations_in_curr_b_record - 146.0) / 170.0));
 
 	    if (additional_1024char_chunks > 0) {
 		for (indx2 = 1; indx2 < additional_1024char_chunks; indx2++) {
@@ -1470,7 +1470,7 @@
 			    curr_elevation = 0;
 			}
 
-			if (output_elevation((long int)round_closest(curr_elevation * raw_dem_2_raw_dsp_scale_factor), fp2) == BRLCAD_ERROR) {
+			if (output_elevation(lrint(round_closest(curr_elevation * raw_dem_2_raw_dsp_scale_factor)), fp2) == BRLCAD_ERROR) {
 			    bu_log("Function 'output_elevation' failed on 'b' record# '%ld', record elevation# '%ld', dem elevation# '%ld', raw elevation value '%ld'.\n", curr_b_record, elevation_number_in_curr_b_record, elevation_number, curr_elevation);
 			    fclose(fp);
 			    fclose(fp2);
@@ -1507,7 +1507,7 @@
 			curr_elevation = 0;
 		    }
 
-		    if (output_elevation((long int)round_closest(curr_elevation * raw_dem_2_raw_dsp_scale_factor), fp2) == BRLCAD_ERROR) {
+		    if (output_elevation(lrint(round_closest(curr_elevation * raw_dem_2_raw_dsp_scale_factor)), fp2) == BRLCAD_ERROR) {
 			bu_log("Function 'output_elevation' failed on 'b' record# '%ld', record elevation# '%ld', dem elevation# '%ld', raw elevation value '%ld'.\n", curr_b_record, elevation_number_in_curr_b_record, elevation_number, curr_elevation);
 			fclose(fp);
 			fclose(fp2);
@@ -1536,7 +1536,7 @@
 		    curr_elevation = 0;
 		}
 
-		if (output_elevation((long int)round_closest(curr_elevation * raw_dem_2_raw_dsp_scale_factor), fp2) == BRLCAD_ERROR) {
+		if (output_elevation(lrint(round_closest(curr_elevation * raw_dem_2_raw_dsp_scale_factor)), fp2) == BRLCAD_ERROR) {
 		    bu_log("Function 'output_elevation' failed on 'b' record# '%ld', record elevation# '%ld', dem elevation# '%ld', raw elevation value '%ld'.\n", curr_b_record, elevation_number_in_curr_b_record, elevation_number, curr_elevation);
 		    fclose(fp);
 		    fclose(fp2);
Index: src/conv/fast4-g.c
===================================================================
--- src/conv/fast4-g.c	(revision 59246)
+++ src/conv/fast4-g.c	(working copy)
@@ -895,7 +895,7 @@
 		ssize_t new_cnt, i;
 		struct bu_list *list_first;
 
-		new_cnt = (ssize_t)ceil(region_id_max/1000.0);
+		new_cnt = lrint(ceil(region_id_max/1000.0));
 		new_head = (struct wmember *)bu_calloc(new_cnt, sizeof(struct wmember), "group_head list");
 		bu_log("ptr->region_id=%d region_id_max=%d new_cnt=%ld\n", ptr->region_id, region_id_max, new_cnt);
 
Index: src/conv/g-dot.c
===================================================================
--- src/conv/g-dot.c	(revision 59246)
+++ src/conv/g-dot.c	(working copy)
@@ -66,13 +66,15 @@
 	bu_log("ERROR: Database read error, skipping %s\n", dp->d_namep);
     }
     comb = (struct rt_comb_internal *)intern.idb_ptr;
-
+    
     if (comb->region_flag) {
-	if (bu_ptbl_ins_unique(&(o->regions), (long *)bu_hash((unsigned char *)dp->d_namep, strlen(dp->d_namep))) == -1) {
+	long hash = bu_hash((unsigned char *)dp->d_namep, strlen(dp->d_namep));
+	if (bu_ptbl_ins_unique(&(o->regions), &hash) == -1) {
 	    fprintf(o->outfp, "\t\"%s\" [ color=blue shape=box3d ];\n", dp->d_namep);
 	}
     } else {
-	if (bu_ptbl_ins_unique(&(o->groups), (long *)bu_hash((unsigned char *)dp->d_namep, strlen(dp->d_namep))) == -1) {
+	long hash = bu_hash((unsigned char *)dp->d_namep, strlen(dp->d_namep));
+	if (bu_ptbl_ins_unique(&(o->groups), &hash) == -1) {
 	    fprintf(o->outfp, "\t\"%s\" [ color=green ];\n", dp->d_namep);
 	}
     }
@@ -145,7 +147,8 @@
     if (!o->outfp)
 	return;
 
-    if (bu_ptbl_ins_unique(&(o->primitives), (long *)bu_hash((unsigned char *)dp->d_namep, strlen(dp->d_namep))) == -1) {
+    long hash = bu_hash((unsigned char *)dp->d_namep, strlen(dp->d_namep));
+    if (bu_ptbl_ins_unique(&(o->primitives), &hash) == -1) {
 	fprintf(o->outfp, "\t\"%s\" [ color=red shape=box rank=min ];\n", dp->d_namep);
     }
 
Index: src/conv/ply-g.c
===================================================================
--- src/conv/ply-g.c	(revision 59246)
+++ src/conv/ply-g.c	(working copy)
@@ -379,7 +379,7 @@
 		if ( fscanf( ply_fp, "%lf", &val_double ) != 1 ) {
 		    bu_exit(1, "ERROR parsing data\n" );
 		}
-		val = (int)floor(val_double);
+		val = lrint(floor(val_double));
 		break;
 	}
     } else {
Index: src/gtools/g_lint.c
===================================================================
--- src/gtools/g_lint.c	(revision 59246)
+++ src/gtools/g_lint.c	(working copy)
@@ -41,7 +41,7 @@
 #define made_it()	bu_log("Made it to %s:%d\n", __FILE__, __LINE__);
 
 #define OPT_STRING	"a:ce:g:opr:st:ux:?h"
-#define RAND_NUM	((fastf_t)rand()/RAND_MAX)
+#define RAND_NUM	(rand()/(fastf_t)RAND_MAX)
 #define RAND_OFFSET	((1 - cell_center) * 	\
 			 (RAND_NUM * celsiz - celsiz / 2))
 #define TITLE_LEN	80
Index: src/lgt/lgt.h
===================================================================
--- src/lgt/lgt.h	(revision 59246)
+++ src/lgt/lgt.h	(working copy)
@@ -130,7 +130,7 @@
     double m_pers_end;
 }
     Movie;
-#define MovieSize(sz, nf)	(int)sqrt((double)(nf)+0.5)*(sz)
+#define MovieSize(sz, nf)	lrint(sqrt((double)(nf)+0.5))*(sz)
 #define IK_INTENSITY	255.0
 #define RGB_INVERSE	(1.0 / IK_INTENSITY)
 #define EYE_SIZE	12.7
Index: src/libbu/rb_create.c
===================================================================
--- src/libbu/rb_create.c	(revision 59246)
+++ src/libbu/rb_create.c	(working copy)
@@ -41,7 +41,7 @@
 	bu_malloc(nm_orders * sizeof(struct bu_rb_node),
 		  "red-black roots");
     tree->rbt_unique = (char *)
-	bu_malloc((size_t) ceil((double) (nm_orders / 8.0)),
+	bu_malloc((size_t) lrint(ceil((double) (nm_orders / 8.0))),
 		  "red-black uniqueness flags");
     RB_NULL(tree) = (struct bu_rb_node *)
 	bu_malloc(sizeof(struct bu_rb_node),
@@ -56,7 +56,7 @@
 	bu_malloc(nm_orders * sizeof(struct bu_rb_node *),
 		  "red-black right children");
     RB_NULL(tree)->rbn_color = (char *)
-	bu_malloc((size_t) ceil((double) (nm_orders / 8.0)),
+	bu_malloc((size_t) lrint(ceil((double) (nm_orders / 8.0))),
 		  "red-black colors");
     RB_NULL(tree)->rbn_size = (int *)
 	bu_malloc(nm_orders * sizeof(int),
Index: src/libbu/rb_insert.c
===================================================================
--- src/libbu/rb_insert.c	(revision 59246)
+++ src/libbu/rb_insert.c	(working copy)
@@ -211,7 +211,7 @@
 	bu_malloc(nm_orders * sizeof(struct bu_rb_node *),
 		  "red-black right children");
     node->rbn_color = (char *)
-	bu_malloc((size_t) ceil((double) (nm_orders / 8.0)),
+	bu_malloc((size_t) lrint(ceil((double) (nm_orders / 8.0))),
 		  "red-black colors");
     node->rbn_size = (int *)
 	bu_malloc(nm_orders * sizeof(int),
Index: src/libbu/tests/bu_heap.c
===================================================================
--- src/libbu/tests/bu_heap.c	(revision 59246)
+++ src/libbu/tests/bu_heap.c	(working copy)
@@ -56,7 +56,7 @@
     srand(time(0));
 
     for (i=0; i<1024*1024*10; i++) {
-	size_t sz = (((double)rand() / (double)(RAND_MAX-1)) * (double)HEAP_BINS) + 1;
+	size_t sz = ((rand() / (double)(RAND_MAX-1)) * (double)HEAP_BINS) + 1;
 	/* bu_log("allocating %d: %zd\n", i, sz); */
 #ifdef USE_MALLOC
 	ptr = malloc(sz);
Index: src/libicv/fileformat.c
===================================================================
--- src/libicv/fileformat.c	(revision 59246)
+++ src/libicv/fileformat.c	(working copy)
@@ -77,7 +77,7 @@
  * return the string as as return type (making the int type be an int*
  * argument instead that gets set).
  */
-int
+ICV_IMAGE_FORMAT
 icv_guess_file_format(const char *filename, char *trimmedname)
 {
     /* look for the FMT: header */
Index: src/librt/cut.c
===================================================================
--- src/librt/cut.c	(revision 59246)
+++ src/librt/cut.c	(working copy)
@@ -312,8 +312,8 @@
 	    RT_NU_GFACTOR_DEFAULT);
     }
 
-    nu_ncells = (int)ceil(2.0 + rtip->rti_nu_gfactor *
-			  pow((double)fromp->bn_len, 1.0/3.0));
+    nu_ncells = lrint(ceil(2.0 + rtip->rti_nu_gfactor *
+			  pow((double)fromp->bn_len, 1.0/3.0)));
     if (rtip->rti_nugrid_dimlimit > 0 &&
 	nu_ncells > rtip->rti_nugrid_dimlimit)
 	nu_ncells = rtip->rti_nugrid_dimlimit;
@@ -797,7 +797,7 @@
      * (2**rtip->rti_cutdepth)*rtip->rti_cutlen potential leaf slots.
      * Also note that solids will typically span several leaves.
      */
-    rtip->rti_cutlen = (int)log((double)(rtip->nsolids+1));  /* ln ~= log2, nsolids+1 to avoid log(0) */
+    rtip->rti_cutlen = lrint(floor(log((double)(rtip->nsolids+1))));  /* ln ~= log2, nsolids+1 to avoid log(0) */
     rtip->rti_cutdepth = 2 * rtip->rti_cutlen;
     if (rtip->rti_cutlen < 3) rtip->rti_cutlen = 3;
     if (rtip->rti_cutdepth < 12) rtip->rti_cutdepth = 12;
Index: src/librt/primitives/dsp/dsp.c
===================================================================
--- src/librt/primitives/dsp/dsp.c	(revision 59246)
+++ src/librt/primitives/dsp/dsp.c	(working copy)
@@ -823,7 +823,7 @@
 		/* initialize the current dsp_bb cell */
 		dsp_bb = &curr->p[y*curr->dim[X]+x];
 		dsp_bb->magic = MAGIC_dsp_bb;
-		n = (int)pow((double)DIM_BB_CHILDREN, (double)curr_layer);
+		n = lrint(pow((double)DIM_BB_CHILDREN, (double)curr_layer));
 		VSET(dsp_bb->dspb_rpp.dsp_min,
 		     x * n, y * n, 0x0ffff);
 		VSET(dsp_bb->dspb_rpp.dsp_max,
Index: src/proc-db/metaball.c
===================================================================
--- src/proc-db/metaball.c	(revision 59246)
+++ src/proc-db/metaball.c	(working copy)
@@ -190,9 +190,9 @@
     mk_id(fp, title);
 
     /* just to make things interesting, make varying sized sets */
-    some = (long)ceil((double)count * (1.0 / 111.0));
-    more = (long)ceil((double)count * (10.0 / 111.0));
-    many = (long)ceil((double)count * (100.0 / 111.0));
+    some = lrint(ceil((double)count * (1.0 / 111.0)));
+    more = lrint(ceil((double)count * (10.0 / 111.0)));
+    many = lrint(ceil((double)count * (100.0 / 111.0)));
 
     /* create individual metaballs with random points using LIBWDB */
     make_meatballs(fp, balls[0], some);
Index: src/rt/view_bot_faces.c
===================================================================
--- src/rt/view_bot_faces.c	(revision 59246)
+++ src/rt/view_bot_faces.c	(working copy)
@@ -292,7 +292,7 @@
     while (entry) {
 	size_t i;
 
-	fprintf(outfp, "BOT: %s\n", Tcl_GetHashKey(&bots, entry));
+	fprintf(outfp, "BOT: %s\n", (char *)Tcl_GetHashKey(&bots, entry));
 	faces = (struct bu_ptbl *)Tcl_GetHashValue(entry);
 	for (i=0; i<BU_PTBL_LEN(faces); i++) {
 	    fprintf(outfp, "\t%lu\n", (unsigned long)BU_PTBL_GET(faces, i));
Index: src/util/plot3rot.c
===================================================================
--- src/util/plot3rot.c	(revision 59246)
+++ src/util/plot3rot.c	(working copy)
@@ -429,10 +429,10 @@
 		    VSET(max, maxx, maxy, -1);
 		    model_rpp(min, max);
 
-		    minx = (long)floor(space_min[X]);
-		    miny = (long)floor(space_min[Y]);
-		    maxx = (long)ceil(space_max[X]);
-		    maxy = (long)ceil(space_max[Y]);
+		    minx = lrint(floor(space_min[X]));
+		    miny = lrint(floor(space_min[Y]));
+		    maxx = lrint(ceil(space_max[X]));
+		    maxy = lrint(ceil(space_max[Y]));
 		    if (minx < -32768) minx = -32768;
 		    if (miny < -32768) miny = -32768;
 		    if (maxx > 32767) maxx = 32767;
