1 /* mpfi_set_uj -- set a MPFI interval from a huge machine unsigned integer
2 
3 Copyright 2017-2018 Free Software Foundation, Inc.
4 Contributed by the AriC project, INRIA.
5 
6 This file is part of the GNU MPFR Library.
7 
8 The GNU MPFI Library is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
12 
13 The GNU MPFI Library is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
16 License for more details.
17 
18 You should have received a copy of the GNU Lesser General Public License
19 along with the GNU MPFI Library; see the file COPYING.LESSER.  If not, see
20 http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
21 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
22 
23 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #endif
26 
27 #include "mpfi-intmax.h"
28 #include "mpfi-impl.h"
29 
30 #ifdef _MPFR_H_HAVE_INTMAX_T
31 
32 int
mpfi_set_uj(mpfi_t a,uintmax_t b)33 mpfi_set_uj (mpfi_t a, uintmax_t b)
34 {
35 int inexact_left, inexact_right, inexact=0;
36 
37   inexact_left = mpfr_set_uj_2exp (&(a->left), b, 0, MPFI_RNDD);
38   inexact_right = mpfr_set_uj_2exp (&(a->right), b, 0, MPFI_RNDU);
39 
40   if (b == 0) {
41     /* fix signed zero so as to return [+0, -0] */
42     mpfr_setsign (&(a->right), &(a->right), 1, MPFI_RNDD);
43   }
44 
45   if (inexact_left)
46     inexact += 1;
47   if (inexact_right)
48     inexact += 2;
49 
50   return inexact;
51 }
52 
53 
54 /* Combined initialization and assignment      */
55 
56 int
mpfi_init_set_uj(mpfi_ptr a,const uintmax_t b)57 mpfi_init_set_uj (mpfi_ptr a, const uintmax_t b)
58 {
59   int inexact_left, inexact_right, inexact = 0;
60 
61   inexact_left = mpfr_init_set_uj (&(a->left), b, MPFI_RNDD);
62   inexact_right = mpfr_init_set_uj (&(a->right), b, MPFI_RNDU);
63 
64   if (b == 0) {
65     /* fix signed zero so as to return [+0, -0] */
66     mpfr_setsign (&(a->left), &(a->left), 0, MPFI_RNDU);
67     mpfr_setsign (&(a->right), &(a->right), 1, MPFI_RNDD);
68   }
69 
70   if (inexact_left)
71     inexact += 1;
72   if (inexact_right)
73     inexact += 2;
74 
75   return inexact;
76 }
77 
78 int
mpfi_set_uj_2exp(mpfi_t x,uintmax_t b,intmax_t e)79 mpfi_set_uj_2exp (mpfi_t x, uintmax_t b, intmax_t e)
80 {
81 int inexact_left, inexact_right, inexact=0;
82 
83   inexact_left = mpfr_set_uj_2exp (&(a->left), b, e, MPFI_RNDD);
84   inexact_right = mpfr_set_uj_2exp (&(a->right), b, e, MPFI_RNDU);
85 
86   if (b == 0) {
87     /* fix signed zero so as to return [+0, -0] */
88     mpfr_setsign (&(a->right), &(a->right), 1, MPFI_RNDD);
89   }
90 
91   if (inexact_left)
92     inexact += 1;
93   if (inexact_right)
94     inexact += 2;
95 
96   return inexact;
97 }
98 
99 #endif
100