xref: /trunk/main/sc/source/core/tool/subtotal.cxx (revision b3f79822)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26 // INCLUDE ---------------------------------------------------------------
27 
28 
29 
30 #include "subtotal.hxx"
31 #include "interpre.hxx"
32 
33 // -----------------------------------------------------------------------
34 
SafePlus(double & fVal1,double fVal2)35 sal_Bool SubTotal::SafePlus(double& fVal1, double fVal2)
36 {
37 	sal_Bool bOk = sal_True;
38 	SAL_MATH_FPEXCEPTIONS_OFF();
39     fVal1 += fVal2;
40 	if (!::rtl::math::isFinite(fVal1))
41 	{
42 		bOk = sal_False;
43 		if (fVal2 > 0.0)
44 			fVal1 = DBL_MAX;
45 		else
46 			fVal1 = -DBL_MAX;
47 	}
48 	return bOk;
49 }
50 
51 
SafeMult(double & fVal1,double fVal2)52 sal_Bool SubTotal::SafeMult(double& fVal1, double fVal2)
53 {
54 	sal_Bool bOk = sal_True;
55 	SAL_MATH_FPEXCEPTIONS_OFF();
56     fVal1 *= fVal2;
57 	if (!::rtl::math::isFinite(fVal1))
58 	{
59 		bOk = sal_False;
60 		fVal1 = DBL_MAX;
61 	}
62 	return bOk;
63 }
64 
65 
SafeDiv(double & fVal1,double fVal2)66 sal_Bool SubTotal::SafeDiv(double& fVal1, double fVal2)
67 {
68 	sal_Bool bOk = sal_True;
69 	SAL_MATH_FPEXCEPTIONS_OFF();
70     fVal1 /= fVal2;
71 	if (!::rtl::math::isFinite(fVal1))
72 	{
73 		bOk = sal_False;
74 		fVal1 = DBL_MAX;
75 	}
76 	return bOk;
77 }
78