1 /* interv_d.c -- Build an interval from two doubles.
2 
3 Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010,
4                      Spaces project, Inria Lorraine
5                      and Salsa project, INRIA Rocquencourt,
6                      and Arenaire project, Inria Rhone-Alpes, France
7                      and Lab. ANO, USTL (Univ. of Lille),  France
8 
9 This file is part of the MPFI Library.
10 
11 The MPFI Library is free software; you can redistribute it and/or modify
12 it under the terms of the GNU Lesser General Public License as published by
13 the Free Software Foundation; either version 2.1 of the License, or (at your
14 option) any later version.
15 
16 The MPFI Library is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
19 License for more details.
20 
21 You should have received a copy of the GNU Lesser General Public License
22 along with the MPFI Library; see the file COPYING.LIB.  If not, write to
23 the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
24 MA 02110-1301, USA. */
25 
26 #include "mpfi-impl.h"
27 
28 int
mpfi_interv_d(mpfi_ptr a,const double b,const double c)29 mpfi_interv_d (mpfi_ptr a, const double b, const double c)
30 {
31   int inexact_left, inexact_right, inexact=0;
32 
33   if (b <= c) {
34     inexact_left = mpfr_set_d (&(a->left), b, MPFI_RNDD);
35     inexact_right = mpfr_set_d (&(a->right), c, MPFI_RNDU);
36   }
37   else {
38     inexact_left = mpfr_set_d (&(a->left), c, MPFI_RNDD);
39     inexact_right = mpfr_set_d (&(a->right), b, MPFI_RNDU);
40   }
41 
42   if ( MPFI_NAN_P (a) )
43     MPFR_RET_NAN;
44 
45   if (inexact_left)
46     inexact += 1;
47   if (inexact_right)
48     inexact += 2;
49 
50   /* do not allow -0 as lower bound */
51   if (mpfr_zero_p (&(a->left)) && mpfr_signbit (&(a->left))) {
52     mpfr_neg (&(a->left), &(a->left), MPFI_RNDU);
53   }
54   /* do not allow +0 as upper bound */
55   if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) {
56     mpfr_neg (&(a->right), &(a->right), MPFI_RNDD);
57   }
58 
59   return inexact;
60 }
61