xref: /trunk/main/formula/inc/formula/errorcodes.hxx (revision 5116778e)
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 #ifndef SC_ERRORCODES_HXX
25 #define SC_ERRORCODES_HXX
26 
27 #include <rtl/math.hxx>
28 #include <tools/solar.h>
29 
30 namespace ScErrorCodes
31 {
32 
33 const sal_uInt16 errIllegalChar          = 501;
34 const sal_uInt16 errIllegalArgument      = 502;
35 const sal_uInt16 errIllegalFPOperation   = 503; // #NUM!
36 const sal_uInt16 errIllegalParameter     = 504;
37 const sal_uInt16 errIllegalJump          = 505;
38 const sal_uInt16 errSeparator            = 506;
39 const sal_uInt16 errPair                 = 507;
40 const sal_uInt16 errPairExpected         = 508;
41 const sal_uInt16 errOperatorExpected     = 509;
42 const sal_uInt16 errVariableExpected     = 510;
43 const sal_uInt16 errParameterExpected    = 511;
44 const sal_uInt16 errCodeOverflow         = 512;
45 const sal_uInt16 errStringOverflow       = 513;
46 const sal_uInt16 errStackOverflow        = 514;
47 const sal_uInt16 errUnknownState         = 515;
48 const sal_uInt16 errUnknownVariable      = 516;
49 const sal_uInt16 errUnknownOpCode        = 517;
50 const sal_uInt16 errUnknownStackVariable = 518;
51 const sal_uInt16 errNoValue              = 519; // #VALUE!
52 const sal_uInt16 errUnknownToken         = 520;
53 const sal_uInt16 errNoCode               = 521; // #NULL!
54 const sal_uInt16 errCircularReference    = 522;
55 const sal_uInt16 errNoConvergence        = 523;
56 const sal_uInt16 errNoRef                = 524; // #REF!
57 const sal_uInt16 errNoName               = 525; // #NAME?
58 const sal_uInt16 errDoubleRef            = 526;
59 const sal_uInt16 errInterpOverflow       = 527;
60 // Not displayed, temporary for TrackFormulas,
61 // Cell depends on another cell that has errCircularReference
62 const sal_uInt16 errTrackFromCircRef     = 528;
63 // ScInterpreter internal:  no numeric value but numeric queried. If this is
64 // set as mnStringNoValueError no error is generated but 0 returned.
65 const sal_uInt16 errCellNoValue          = 529;
66 // Interpreter: needed AddIn not found
67 const sal_uInt16 errNoAddin              = 530;
68 // Interpreter: needed Macro not found
69 const sal_uInt16 errNoMacro              = 531;
70 // Interpreter: Division by zero
71 const sal_uInt16 errDivisionByZero       = 532; // #DIV/0!
72 // Compiler: a non-simple (str,err,val) value was put in an array
73 const sal_uInt16 errNestedArray          = 533;
74 // ScInterpreter internal:  no numeric value but numeric queried. If this is
75 // temporarily (!) set as mnStringNoValueError, the error is generated and can
76 // be used to distinguish that condition from all other (inherited) errors. Do
77 // not use for anything else! Never push or inherit the error otherwise!
78 const sal_uInt16 errNotNumericString     = 534;
79 
80 // Interpreter: NA() not available condition, not a real error
81 const sal_uInt16 NOTAVAILABLE            = 0x7fff;
82 
83 
84 /** Unconditionally construct a double value of NAN where the lower bits
85     represent an interpreter error code. */
CreateDoubleError(sal_uInt16 nErr)86 inline double CreateDoubleError( sal_uInt16 nErr )
87 {
88     union
89     {
90         double fVal;
91         sal_math_Double smVal;
92     };
93     ::rtl::math::setNan( &fVal );
94     smVal.nan_parts.fraction_lo = nErr;
95     return fVal;
96 }
97 
98 
99 /** Recreate the error code of a coded double error, if any. */
GetDoubleErrorValue(double fVal)100 inline sal_uInt16 GetDoubleErrorValue( double fVal )
101 {
102     if ( ::rtl::math::isFinite( fVal ) )
103         return 0;
104     if ( ::rtl::math::isInf( fVal ) )
105         return errIllegalFPOperation;       // normal INF
106     sal_uInt32 nErr = reinterpret_cast< sal_math_Double * >(
107             &fVal)->nan_parts.fraction_lo;
108     if ( nErr & 0xffff0000 )
109         return errNoValue;                  // just a normal NAN
110     return (sal_uInt16)(nErr & 0x0000ffff);     // any other error
111 }
112 
113 } // namespace ScErrorCodes
114 
115 // yes, exceptionally we put a "using namespace" in a header file..
116 using namespace ScErrorCodes;
117 
118 #endif // SC_ERRORCODES_HXX
119