diff options
-rw-r--r-- | doc/HISTORY | 3 | ||||
-rw-r--r-- | lib/util/pm_c_util.h | 7 |
2 files changed, 9 insertions, 1 deletions
diff --git a/doc/HISTORY b/doc/HISTORY index afff88fc..4027d319 100644 --- a/doc/HISTORY +++ b/doc/HISTORY @@ -14,6 +14,9 @@ not yet BJH Release 10.86.00 pamscale: Add -reportonly + libnetpbm: Fix ROUNDU so it properly rounds up fractions of + exactly half. Affects many programs. + pamstretch: Reject very large scale factors instead of producing incorrect output. diff --git a/lib/util/pm_c_util.h b/lib/util/pm_c_util.h index 4890da05..718be369 100644 --- a/lib/util/pm_c_util.h +++ b/lib/util/pm_c_util.h @@ -19,7 +19,12 @@ #undef ROUND #define ROUND(X) (((X) >= 0) ? (int)((X)+0.5) : (int)((X)-0.5)) #undef ROUNDU -#define ROUNDU(X) ((unsigned int)((X)+0.5)) +#define ROUNDU(X) ((unsigned int)((X)+0.5+1e-15)) + /* We add the 1e-15 epsilon because for repeatability we want exactly half + to round up. But the imprecision of the floating point arithmetic can + cause a number that is supposed to be exactly half to be slightly less + than half in reality. Without this adjustment, it would round down. + */ /* ROUNDUP rounds up to a specified multiple. E.g. ROUNDUP(22, 8) == 24 */ |