]> git.sur5r.net Git - i3/i3/commitdiff
Bugfix: Use more precise floating point arithmetic (Thanks helgiks)
authorMichael Stapelberg <michael@stapelberg.de>
Tue, 8 Dec 2009 10:48:25 +0000 (11:48 +0100)
committerMichael Stapelberg <michael@stapelberg.de>
Tue, 8 Dec 2009 10:48:25 +0000 (11:48 +0100)
This prevents errors in rounding leading to an unoccupied space of
-1 which in turn leads to infinity when calculating the new size
of a container after resizing.

src/layout.c

index 101b1ddb853187d5d764915dbdc035e40cc5b2fc..80707319aabd9c9c952d2a65ede165eb0b463998 100644 (file)
@@ -47,37 +47,37 @@ static bool update_if_necessary(uint32_t *destination, const uint32_t new_value)
  *
  */
 int get_unoccupied_x(Workspace *workspace) {
-        int unoccupied = workspace->rect.width;
-        float default_factor = ((float)workspace->rect.width / workspace->cols) / workspace->rect.width;
+        double unoccupied = workspace->rect.width;
+        double default_factor = ((float)workspace->rect.width / workspace->cols) / workspace->rect.width;
 
-        LOG("get_unoccupied_x(), starting with %d, default_factor = %f\n", unoccupied, default_factor);
+        LOG("get_unoccupied_x(), starting with %f, default_factor = %f\n", unoccupied, default_factor);
 
         for (int cols = 0; cols < workspace->cols; cols++) {
-                LOG("width_factor[%d] = %f\n", cols, workspace->width_factor[cols]);
+                LOG("width_factor[%d] = %f, unoccupied = %f\n", cols, workspace->width_factor[cols], unoccupied);
 
                 if (workspace->width_factor[cols] == 0)
                         unoccupied -= workspace->rect.width * default_factor;
         }
 
-        LOG("unoccupied space: %d\n", unoccupied);
+        LOG("unoccupied space: %f\n", unoccupied);
         return unoccupied;
 }
 
 /* See get_unoccupied_x() */
 int get_unoccupied_y(Workspace *workspace) {
         int height = workspace_height(workspace);
-        int unoccupied = height;
-        float default_factor = ((float)height / workspace->rows) / height;
+        double unoccupied = height;
+        double default_factor = ((float)height / workspace->rows) / height;
 
-        LOG("get_unoccupied_y(), starting with %d, default_factor = %f\n", unoccupied, default_factor);
+        LOG("get_unoccupied_y(), starting with %f, default_factor = %f\n", unoccupied, default_factor);
 
         for (int rows = 0; rows < workspace->rows; rows++) {
-                LOG("height_factor[%d] = %f\n", rows, workspace->height_factor[rows]);
+                LOG("height_factor[%d] = %f, unoccupied = %f\n", rows, workspace->height_factor[rows], unoccupied);
                 if (workspace->height_factor[rows] == 0)
                         unoccupied -= height * default_factor;
         }
 
-        LOG("unoccupied space: %d\n", unoccupied);
+        LOG("unoccupied space: %f\n", unoccupied);
         return unoccupied;
 }