X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fround.c;h=eeca4b9ca0212fba66cfc52cb16456ac3d8255e7;hb=c7a120f0df82737c24832f6a0c6cc7e1bfd4e671;hp=df6232d51311ff3ba362740284189262ea9ace68;hpb=f19c2f156e388e1da7ab9b13250dfeb380c0ab84;p=gnulib.git diff --git a/lib/round.c b/lib/round.c index df6232d51..eeca4b9ca 100644 --- a/lib/round.c +++ b/lib/round.c @@ -1,5 +1,5 @@ /* Round toward nearest, breaking ties away from zero. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2009 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -114,39 +114,39 @@ FLOOR_FREE_ROUND (DOUBLE x) { /* Avoid rounding error for x = 0.5 - 2^(-MANT_DIG-1). */ if (z < L_(0.5)) - z = L_(0.0); + z = L_(0.0); /* Avoid rounding errors for values near 2^k, where k >= MANT_DIG-1. */ else if (z < TWO_MANT_DIG) - { - /* Add 0.5 to the absolute value. */ - y = z += L_(0.5); - /* Round to the next integer (nearest or up or down, doesn't + { + /* Add 0.5 to the absolute value. */ + y = z += L_(0.5); + /* Round to the next integer (nearest or up or down, doesn't matter). */ - z += TWO_MANT_DIG; - z -= TWO_MANT_DIG; - /* Enforce rounding down. */ - if (z > y) - z -= L_(1.0); - } + z += TWO_MANT_DIG; + z -= TWO_MANT_DIG; + /* Enforce rounding down. */ + if (z > y) + z -= L_(1.0); + } } else if (z < L_(0.0)) { /* Avoid rounding error for x = -(0.5 - 2^(-MANT_DIG-1)). */ if (z > - L_(0.5)) - z = L_(0.0); + z = L_(0.0); /* Avoid rounding errors for values near -2^k, where k >= MANT_DIG-1. */ else if (z > -TWO_MANT_DIG) - { - /* Add 0.5 to the absolute value. */ - y = z -= L_(0.5); - /* Round to the next integer (nearest or up or down, doesn't + { + /* Add 0.5 to the absolute value. */ + y = z -= L_(0.5); + /* Round to the next integer (nearest or up or down, doesn't matter). */ - z -= TWO_MANT_DIG; - z += TWO_MANT_DIG; - /* Enforce rounding up. */ - if (z < y) - z += L_(1.0); - } + z -= TWO_MANT_DIG; + z += TWO_MANT_DIG; + /* Enforce rounding up. */ + if (z < y) + z += L_(1.0); + } } return z; }