diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2019-01-13 22:09:23 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2019-01-13 22:09:23 +0000 |
commit | 6a1dcaafddd50c0846098db4d1d44c2be0131f69 (patch) | |
tree | c24f3b73f53b5b7d28d2792688b84fffc7a36b34 /lib | |
parent | d9a45f5fc22d3cf8bc270feea3c155fad43933eb (diff) | |
download | netpbm-mirror-6a1dcaafddd50c0846098db4d1d44c2be0131f69.tar.gz netpbm-mirror-6a1dcaafddd50c0846098db4d1d44c2be0131f69.tar.xz netpbm-mirror-6a1dcaafddd50c0846098db4d1d44c2be0131f69.zip |
Add epsilon before rounding, to take care of fractions that should be exactly
half but are slightly less because of imprecision in floating point arithmetic git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@3499 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/util/pm_c_util.h | 7 |
1 files changed, 6 insertions, 1 deletions
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 */ |