1 /* Division_Floating_Point_Expression class implementation:
2 non-inline template functions.
3 Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
4 Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com)
5
6 This file is part of the Parma Polyhedra Library (PPL).
7
8 The PPL is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
12
13 The PPL is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software Foundation,
20 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
21
22 For the most up-to-date information see the Parma Polyhedra Library
23 site: http://bugseng.com/products/ppl/ . */
24
25 #ifndef PPL_Division_Floating_Point_Expression_templates_hh
26 #define PPL_Division_Floating_Point_Expression_templates_hh 1
27
28 namespace Parma_Polyhedra_Library {
29
30 template <typename FP_Interval_Type, typename FP_Format>
31 bool Division_Floating_Point_Expression<FP_Interval_Type, FP_Format>
linearize(const FP_Interval_Abstract_Store & int_store,const FP_Linear_Form_Abstract_Store & lf_store,FP_Linear_Form & result) const32 ::linearize(const FP_Interval_Abstract_Store& int_store,
33 const FP_Linear_Form_Abstract_Store& lf_store,
34 FP_Linear_Form& result) const {
35 FP_Linear_Form linearized_second_operand;
36 if (!second_operand->linearize(int_store, lf_store,
37 linearized_second_operand)) {
38 return false;
39 }
40 FP_Interval_Type intervalized_second_operand;
41 this->intervalize(linearized_second_operand, int_store,
42 intervalized_second_operand);
43
44 // Check if we may divide by zero.
45 if (intervalized_second_operand.lower() <= 0
46 && intervalized_second_operand.upper() >= 0) {
47 return false;
48 }
49
50 if (!first_operand->linearize(int_store, lf_store, result)) {
51 return false;
52 }
53 FP_Linear_Form rel_error;
54 relative_error(result, rel_error);
55 result /= intervalized_second_operand;
56 rel_error /= intervalized_second_operand;
57 result += rel_error;
58 result += this->absolute_error;
59 return !this->overflows(result);
60 }
61
62 } // namespace Parma_Polyhedra_Library
63
64 #endif // !defined(PPL_Division_Floating_Point_Expression_templates_hh)
65