Skip to content

Tests for metal_div_round_up/down fail #364

@edmooring

Description

@edmooring

Running test-all-metal-shared results in the following failure for utilities.c:

metal: error: -10 divided by 3 rounded down is -3 instead of -4 and rounded up is -2 instead of -3

The relevant code in lib/utilities.h is:

/** Divide (and round down). */
#define metal_div_round_down(num, den)                  \
        ((num) / (den))

/** Divide (and round up). */
#define metal_div_round_up(num, den)                    \
        metal_div_round_down((num) + (den) - 1, (den))

This is wrong for negative results because C integer division truncates toward zero, so for negative results, it rounds up.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions