Replace "round(x)" with "(int)(0.5 + x)"

round() is a C99 addition, so causes portability problems:
different C library versions require different #defines to
enable it. So simply avoid using it.
This commit is contained in:
Siegfried-Angel Gevatter Pujals 2009-10-01 22:32:38 +02:00
parent 90ddad7ba1
commit 243824ab80
3 changed files with 13 additions and 16 deletions

View File

@ -35,7 +35,6 @@
#include "config.h" #include "config.h"
#endif #endif
#include <math.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -165,7 +164,7 @@ st_button_style_changed (StWidget *widget)
spacing = 6; spacing = 6;
st_theme_node_get_length (theme_node, "border-spacing", FALSE, &spacing); st_theme_node_get_length (theme_node, "border-spacing", FALSE, &spacing);
priv->spacing = round (spacing); priv->spacing = (int)(0.5 + spacing);
/* update the label styling */ /* update the label styling */
st_button_update_label_style (button); st_button_update_label_style (button);

View File

@ -1,6 +1,5 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
#include <math.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -1565,7 +1564,7 @@ font_weight_from_term (CRTerm *term,
if (term->content.num->type != NUM_GENERIC) if (term->content.num->type != NUM_GENERIC)
return FALSE; return FALSE;
weight_int = (int)(term->content.num->val + 0.5); weight_int = (int)(0.5 + term->content.num->val);
*weight = weight_int; *weight = weight_int;
*weight_absolute = TRUE; *weight_absolute = TRUE;
@ -1899,7 +1898,7 @@ st_theme_node_get_border_image (StThemeNode *node)
if (term->content.num->type == NUM_GENERIC) if (term->content.num->type == NUM_GENERIC)
{ {
borders[n_borders] = round (0.5 + term->content.num->val); borders[n_borders] = (int)(0.5 + term->content.num->val);
n_borders++; n_borders++;
} }
else if (term->content.num->type == NUM_PERCENTAGE) else if (term->content.num->type == NUM_PERCENTAGE)
@ -1962,15 +1961,15 @@ st_theme_node_get_border_image (StThemeNode *node)
static float static float
get_width_inc (StThemeNode *node) get_width_inc (StThemeNode *node)
{ {
return (round (node->border_width[ST_SIDE_LEFT]) + node->padding[ST_SIDE_LEFT] + return ((int)(0.5 + node->border_width[ST_SIDE_LEFT]) + node->padding[ST_SIDE_LEFT] +
round (node->border_width[ST_SIDE_RIGHT]) + node->padding[ST_SIDE_RIGHT]); (int)(0.5 + node->border_width[ST_SIDE_RIGHT]) + node->padding[ST_SIDE_RIGHT]);
} }
static float static float
get_height_inc (StThemeNode *node) get_height_inc (StThemeNode *node)
{ {
return (round (node->border_width[ST_SIDE_TOP]) + node->padding[ST_SIDE_TOP] + return ((int)(0.5 + node->border_width[ST_SIDE_TOP]) + node->padding[ST_SIDE_TOP] +
round (node->border_width[ST_SIDE_BOTTOM]) + node->padding[ST_SIDE_BOTTOM]); (int)(0.5 + node->border_width[ST_SIDE_BOTTOM]) + node->padding[ST_SIDE_BOTTOM]);
} }
/** /**
@ -2103,10 +2102,10 @@ st_theme_node_get_content_box (StThemeNode *node,
ensure_borders (node); ensure_borders (node);
content_box->x1 = round (node->border_width[ST_SIDE_LEFT]) + node->padding[ST_SIDE_LEFT]; content_box->x1 = (int)(0.5 + node->border_width[ST_SIDE_LEFT]) + node->padding[ST_SIDE_LEFT];
content_box->y1 = round (node->border_width[ST_SIDE_TOP]) + node->padding[ST_SIDE_TOP]; content_box->y1 = (int)(0.5 + node->border_width[ST_SIDE_TOP]) + node->padding[ST_SIDE_TOP];
content_box->x2 = allocation->x2 - allocation->x1 - (round (node->border_width[ST_SIDE_RIGHT]) + node->padding[ST_SIDE_RIGHT]); content_box->x2 = allocation->x2 - allocation->x1 - ((int)(0.5 + node->border_width[ST_SIDE_RIGHT]) + node->padding[ST_SIDE_RIGHT]);
content_box->y2 = allocation->y2 - allocation->y1 - (round (node->border_width[ST_SIDE_BOTTOM]) + node->padding[ST_SIDE_BOTTOM]); content_box->y2 = allocation->y2 - allocation->y1 - ((int)(0.5 + node->border_width[ST_SIDE_BOTTOM]) + node->padding[ST_SIDE_BOTTOM]);
} }

View File

@ -28,7 +28,6 @@
#include "config.h" #include "config.h"
#endif #endif
#include <math.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -533,7 +532,7 @@ st_widget_real_style_changed (StWidget *self)
double width = st_theme_node_get_border_width (theme_node, side); double width = st_theme_node_get_border_width (theme_node, side);
if (width > 0.5) if (width > 0.5)
{ {
border_width = round (width); border_width = (int)(0.5 + width);
st_theme_node_get_border_color (theme_node, side, &border_color); st_theme_node_get_border_color (theme_node, side, &border_color);
break; break;
} }
@ -544,7 +543,7 @@ st_widget_real_style_changed (StWidget *self)
double radius = st_theme_node_get_border_radius (theme_node, corner); double radius = st_theme_node_get_border_radius (theme_node, corner);
if (radius > 0.5) if (radius > 0.5)
{ {
border_radius = round (radius); border_radius = (int)(0.5 + radius);
break; break;
} }
} }