1 /* Init class declaration.
2    Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
3    Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com)
4 
5 This file is part of the Parma Polyhedra Library (PPL).
6 
7 The PPL is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 The PPL is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
20 
21 For the most up-to-date information see the Parma Polyhedra Library
22 site: http://bugseng.com/products/ppl/ . */
23 
24 #ifndef PPL_Init_defs_hh
25 #define PPL_Init_defs_hh 1
26 
27 #include "Init_types.hh"
28 #include "fpu_types.hh"
29 
30 namespace Parma_Polyhedra_Library {
31 
32 /*! \brief
33   Sets the FPU rounding mode so that the PPL abstractions based on
34   floating point numbers work correctly.
35 
36   This is performed automatically at initialization-time.  Calling
37   this function is needed only if restore_pre_PPL_rounding() has been
38   previously called.
39 */
40 void set_rounding_for_PPL();
41 
42 /*! \brief
43   Sets the FPU rounding mode as it was before initialization of the PPL.
44 
45   This is important if the application uses floating-point computations
46   outside the PPL.  It is crucial when the application uses functions
47   from a mathematical library that are not guaranteed to work correctly
48   under all rounding modes.
49 
50   After calling this function it is absolutely necessary to call
51   set_rounding_for_PPL() before using any PPL abstractions based on
52   floating point numbers.
53   This is performed automatically at finalization-time.
54 */
55 void restore_pre_PPL_rounding();
56 
57 } // namespace Parma_Polyhedra_Library
58 
59 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
60 //! Class for initialization and finalization.
61 /*! \ingroup PPL_CXX_interface
62   <EM>Nifty Counter</EM> initialization class,
63   ensuring that the library is initialized only once
64   and before its first use.
65   A count of the number of translation units using the library
66   is maintained. A static object of Init type will be declared
67   by each translation unit using the library.  As a result,
68   only one of them will initialize and properly finalize
69   the library.
70 */
71 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
72 class Parma_Polyhedra_Library::Init {
73 public:
74   //! Initializes the PPL.
75   Init();
76 
77   //! Finalizes the PPL.
78   ~Init();
79 
80 private:
81   /*! \brief
82     Default precision parameter used for irrational calculations.
83 
84     The default is chosen to have a precision greater than most
85     precise IEC 559 floating point (112 bits of mantissa).
86   */
87   static const unsigned DEFAULT_IRRATIONAL_PRECISION = 128U;
88 
89   //! Count the number of objects created.
90   static unsigned int count;
91   static fpu_rounding_direction_type old_rounding_direction;
92 
93   friend void set_rounding_for_PPL();
94   friend void restore_pre_PPL_rounding();
95 };
96 
97 #include "Init_inlines.hh"
98 
99 
100 #endif // !defined(PPL_Init_defs_hh)
101