X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Ffloor.c;h=86ae3ac8b49c02f9215ebb79ff62d449f8412ce2;hb=06ef7ef9193810369b351b00548cfaa48fad0952;hp=7016ed476eb1f1321417d98c3f02bcaceb355cc7;hpb=441aa3044f43e5572f58c354f01e6bc070acd5c7;p=gnulib.git diff --git a/lib/floor.c b/lib/floor.c index 7016ed476..86ae3ac8b 100644 --- a/lib/floor.c +++ b/lib/floor.c @@ -1,5 +1,5 @@ /* Round towards negative infinity. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2010-2012 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 @@ -16,7 +16,9 @@ /* Written by Bruno Haible , 2007. */ -#include +#if ! defined USE_LONG_DOUBLE +# include +#endif /* Specification. */ #include @@ -65,8 +67,12 @@ FUNC (DOUBLE x) if (z > L_(0.0)) { + /* For 0 < x < 1, return +0.0 even if the current rounding mode is + FE_DOWNWARD. */ + if (z < L_(1.0)) + z = L_(0.0); /* Avoid rounding errors for values near 2^k, where k >= MANT_DIG-1. */ - if (z < TWO_MANT_DIG) + else if (z < TWO_MANT_DIG) { /* Round to the next integer (nearest or up or down, doesn't matter). */ z += TWO_MANT_DIG;