LibreOffice Module formula (master) 1
errorcodes.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#ifndef INCLUDED_FORMULA_ERRORCODES_HXX
21#define INCLUDED_FORMULA_ERRORCODES_HXX
22
23#include <sal/mathconf.h>
24#include <sal/types.h>
25
26#include <cmath>
27#include <limits>
28
29// Store as 16-bits, since error values are stored in tokens and formula results,
30// and that can matter
31enum class FormulaError : sal_uInt16
32{
33 NONE = 0,
34
35 IllegalChar = 501,
36 IllegalArgument = 502,
37 IllegalFPOperation = 503, // #NUM!
38 IllegalParameter = 504,
39 Pair = 507,
40 PairExpected = 508,
41 OperatorExpected = 509,
42 VariableExpected = 510,
44 CodeOverflow = 512,
45 StringOverflow = 513,
46 StackOverflow = 514,
47 UnknownState = 515,
48 UnknownVariable = 516,
49 UnknownOpCode = 517,
51 NoValue = 519, // #VALUE!
52 UnknownToken = 520,
53 NoCode = 521, // #NULL!
55 NoConvergence = 523,
56 NoRef = 524, // #REF!
57 NoName = 525, // #NAME?
58// ScInterpreter internal: no numeric value but numeric queried. If this is
59// set as mnStringNoValueError no error is generated but 0 returned.
60 CellNoValue = 529,
61// Interpreter: needed AddIn not found
62 NoAddin = 530,
63// Interpreter: needed Macro not found
64 NoMacro = 531,
65// Interpreter: Division by zero
66 DivisionByZero = 532, // #DIV/0!
67// Compiler: a non-simple (str,err,val) value was put in an array
68 NestedArray = 533,
69// ScInterpreter internal: no numeric value but numeric queried. If this is
70// temporarily (!) set as mnStringNoValueError, the error is generated and can
71// be used to distinguish that condition from all other (inherited) errors. Do
72// not use for anything else! Never push or inherit the error otherwise!
73 NotNumericString = 534,
74// ScInterpreter internal: jump matrix already has a result at this position,
75// do not overwrite in case of empty code path.
76 JumpMatHasResult = 535,
77// ScInterpreter internal: (matrix) element is not a numeric value, i.e.
78// string or empty, to be distinguished from the general FormulaError::NoValue NAN and not
79// to be used as result.
80 ElementNaN = 536,
81// ScInterpreter/ScFormulaCell internal: keep dirty, retry interpreting next
82// round.
83 RetryCircular = 537,
84// If matrix could not be allocated.
85 MatrixSize = 538,
86// Bad inline array content, non-value/non-string.
87 BadArrayContent = 539,
88// Interpreter: signal result not available because updating links is not
89// allowed (yet) and tell to try hybrid string as result.
91
92// Interpreter: NA() not available condition, not a real error
93 NotAvailable = 0x7fff
94};
95
98inline double CreateDoubleError( FormulaError nErr )
99{
100 sal_math_Double smVal;
101 smVal.value = std::numeric_limits<double>::quiet_NaN();
102 smVal.nan_parts.fraction_lo = static_cast<unsigned>(nErr);
103 return smVal.value;
104}
105
108{
109 if ( std::isfinite( fVal ) )
110 return FormulaError::NONE;
111 if ( std::isinf( fVal ) )
112 return FormulaError::IllegalFPOperation; // normal INF
113 sal_uInt32 nErr = reinterpret_cast< sal_math_Double * >( &fVal)->nan_parts.fraction_lo;
114 if ( nErr & 0xffff0000 )
115 return FormulaError::NoValue; // just a normal NAN
116 if (!nErr)
117 // Another NAN, e.g. -nan(0x8000000000000) from calculating with -inf
119 // Any other error known to us as error code.
120 return static_cast<FormulaError>(nErr & 0x0000ffff);
121}
122
129{
130 // Every value has to be handled explicitly, do not add a default case to
131 // let the compiler complain if a value is missing.
132 switch (nErr)
133 {
135 return false;
136
160 return true;
161
163 return false;
164
170 return true;
171
176 return false;
177
180 return true;
181
183 return false;
184 }
185 return false;
186}
187
188#endif // INCLUDED_FORMULA_ERRORCODES_HXX
189
190/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool isPublishedFormulaError(FormulaError nErr)
Error values that are accepted as detailed "#ERRxxx!" constants.
Definition: errorcodes.hxx:128
FormulaError
Definition: errorcodes.hxx:32
@ LinkFormulaNeedingCheck
double CreateDoubleError(FormulaError nErr)
Unconditionally construct a double value of NAN where the lower bits represent an interpreter error c...
Definition: errorcodes.hxx:98
FormulaError GetDoubleErrorValue(double fVal)
Recreate the error code of a coded double error, if any.
Definition: errorcodes.hxx:107
if(aStr !=aBuf) UpdateName_Impl(m_xFollowLb.get()
NONE