summaryrefslogtreecommitdiffstats
path: root/gl/floor.c
diff options
context:
space:
mode:
authorHolger Weiss <holger@zedat.fu-berlin.de>2013-08-19 23:27:12 +0200
committerHolger Weiss <holger@zedat.fu-berlin.de>2013-08-19 23:27:12 +0200
commit26fbe7f1e68bb0c96da32491efcf3696fe6c299b (patch)
treec4d95289187a64e9c7517bf73d8208026c3d2fb3 /gl/floor.c
parent5f79e3e9f62ca5487d9881973149136ba1d19d3e (diff)
downloadmonitoring-plugins-26fbe7f1e68bb0c96da32491efcf3696fe6c299b.tar.gz
Sync with the latest Gnulib code (6f2d632)
Diffstat (limited to 'gl/floor.c')
-rw-r--r--gl/floor.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/gl/floor.c b/gl/floor.c
index 593b5268..cf29b196 100644
--- a/gl/floor.c
+++ b/gl/floor.c
@@ -1,5 +1,5 @@
1/* Round towards negative infinity. 1/* Round towards negative infinity.
2 Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc. 2 Copyright (C) 2007, 2010-2013 Free Software Foundation, Inc.
3 3
4 This program is free software: you can redistribute it and/or modify 4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by 5 it under the terms of the GNU General Public License as published by
@@ -16,7 +16,9 @@
16 16
17/* Written by Bruno Haible <bruno@clisp.org>, 2007. */ 17/* Written by Bruno Haible <bruno@clisp.org>, 2007. */
18 18
19#include <config.h> 19#if ! defined USE_LONG_DOUBLE
20# include <config.h>
21#endif
20 22
21/* Specification. */ 23/* Specification. */
22#include <math.h> 24#include <math.h>
@@ -40,6 +42,12 @@
40# define L_(literal) literal##f 42# define L_(literal) literal##f
41#endif 43#endif
42 44
45/* MSVC with option -fp:strict refuses to compile constant initializers that
46 contain floating-point operations. Pacify this compiler. */
47#ifdef _MSC_VER
48# pragma fenv_access (off)
49#endif
50
43/* 2^(MANT_DIG-1). */ 51/* 2^(MANT_DIG-1). */
44static const DOUBLE TWO_MANT_DIG = 52static const DOUBLE TWO_MANT_DIG =
45 /* Assume MANT_DIG <= 5 * 31. 53 /* Assume MANT_DIG <= 5 * 31.
@@ -65,8 +73,12 @@ FUNC (DOUBLE x)
65 73
66 if (z > L_(0.0)) 74 if (z > L_(0.0))
67 { 75 {
76 /* For 0 < x < 1, return +0.0 even if the current rounding mode is
77 FE_DOWNWARD. */
78 if (z < L_(1.0))
79 z = L_(0.0);
68 /* Avoid rounding errors for values near 2^k, where k >= MANT_DIG-1. */ 80 /* Avoid rounding errors for values near 2^k, where k >= MANT_DIG-1. */
69 if (z < TWO_MANT_DIG) 81 else if (z < TWO_MANT_DIG)
70 { 82 {
71 /* Round to the next integer (nearest or up or down, doesn't matter). */ 83 /* Round to the next integer (nearest or up or down, doesn't matter). */
72 z += TWO_MANT_DIG; 84 z += TWO_MANT_DIG;