LibreOffice Module basic (master) 1
sbxdbl.cxx
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#include <config_features.h>
21
23#include "sbxconv.hxx"
24#include <rtlproto.hxx>
25#include <runtime.hxx>
26
27double ImpGetDouble( const SbxValues* p )
28{
29 double nRes;
30 switch( +p->eType )
31 {
32 case SbxNULL:
34 [[fallthrough]];
35 case SbxEMPTY:
36 nRes = 0; break;
37 case SbxCHAR:
38 nRes = p->nChar; break;
39 case SbxBYTE:
40 nRes = p->nByte; break;
41 case SbxINTEGER:
42 case SbxBOOL:
43 nRes = p->nInteger; break;
44 case SbxERROR:
45 case SbxUSHORT:
46 nRes = p->nUShort; break;
47 case SbxLONG:
48 nRes = p->nLong; break;
49 case SbxULONG:
50 nRes = p->nULong; break;
51 case SbxSINGLE:
52 nRes = p->nSingle; break;
53 case SbxDATE:
54 case SbxDOUBLE:
55 nRes = p->nDouble; break;
56 case SbxCURRENCY:
57 nRes = ImpCurrencyToDouble( p->nInt64 ); break;
58 case SbxSALINT64:
59 nRes = static_cast< double >(p->nInt64); break;
60 case SbxSALUINT64:
61 nRes = ImpSalUInt64ToDouble( p->uInt64 ); break;
62 case SbxDECIMAL:
63 case SbxBYREF | SbxDECIMAL:
64 if (!p->pDecimal || !p->pDecimal->getDouble(nRes))
65 nRes = 0.0;
66 break;
67 case SbxBYREF | SbxSTRING:
68 case SbxSTRING:
69 case SbxLPSTR:
70 if( !p->pOUString )
71 {
72 nRes = 0;
73#if HAVE_FEATURE_SCRIPTING
74 if ( SbiRuntime::isVBAEnabled() )// VBA only behaviour
76#endif
77 }
78 else
79 {
80 double d;
82 if( ImpScan( *p->pOUString, d, t, nullptr, !LibreOffice6FloatingPointMode() ) != ERRCODE_NONE )
83 {
84 nRes = 0;
85#if HAVE_FEATURE_SCRIPTING
86 if ( SbiRuntime::isVBAEnabled() )// VBA only behaviour
88#endif
89 }
90 else
91 nRes = d;
92 }
93 break;
94 case SbxOBJECT:
95 {
96 SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
97 if( pVal )
98 nRes = pVal->GetDouble();
99 else
100 {
102 }
103 break;
104 }
105
106 case SbxBYREF | SbxCHAR:
107 nRes = *p->pChar; break;
108 case SbxBYREF | SbxBYTE:
109 nRes = *p->pByte; break;
110 case SbxBYREF | SbxINTEGER:
111 case SbxBYREF | SbxBOOL:
112 nRes = *p->pInteger; break;
113 case SbxBYREF | SbxLONG:
114 nRes = *p->pLong; break;
115 case SbxBYREF | SbxULONG:
116 nRes = *p->pULong; break;
117 case SbxBYREF | SbxERROR:
118 case SbxBYREF | SbxUSHORT:
119 nRes = *p->pUShort; break;
120 case SbxBYREF | SbxSINGLE:
121 nRes = *p->pSingle; break;
122 case SbxBYREF | SbxDATE:
123 case SbxBYREF | SbxDOUBLE:
124 nRes = *p->pDouble; break;
125 case SbxBYREF | SbxCURRENCY:
126 nRes = ImpCurrencyToDouble( *p->pnInt64 ); break;
127 case SbxBYREF | SbxSALINT64:
128 nRes = static_cast< double >(*p->pnInt64); break;
129 case SbxBYREF | SbxSALUINT64:
130 nRes = ImpSalUInt64ToDouble( *p->puInt64 ); break;
131
132 default:
134 }
135 return nRes;
136}
137
138void ImpPutDouble( SbxValues* p, double n, bool bCoreString )
139{
140 SbxValues aTmp;
141start:
142 switch( +p->eType )
143 {
144 // Here are tests necessary
145 case SbxCHAR:
146 aTmp.pChar = &p->nChar; goto direct;
147 case SbxBYTE:
148 aTmp.pByte = &p->nByte; goto direct;
149 case SbxINTEGER:
150 case SbxBOOL:
151 aTmp.pInteger = &p->nInteger; goto direct;
152 case SbxLONG:
153 aTmp.pLong = &p->nLong; goto direct;
154 case SbxULONG:
155 aTmp.pULong = &p->nULong; goto direct;
156 case SbxERROR:
157 case SbxUSHORT:
158 aTmp.pUShort = &p->nUShort; goto direct;
159 case SbxSINGLE:
160 aTmp.pSingle = &p->nSingle; goto direct;
161 case SbxDECIMAL:
162 case SbxBYREF | SbxDECIMAL:
163 {
164 SbxDecimal* pDec = ImpCreateDecimal( p );
165 if( !pDec->setDouble( n ) )
167 break;
168 }
169 direct:
170 aTmp.eType = SbxDataType( p->eType | SbxBYREF );
171 p = &aTmp; goto start;
172
173 case SbxCURRENCY:
174 if( n > SbxMAXCURR )
175 {
177 }
178 else if( n < SbxMINCURR )
179 {
181 }
182 p->nInt64 = ImpDoubleToCurrency( n );
183 break;
184
185 // from here on no longer
186 case SbxSALINT64:
187 p->nInt64 = ImpDoubleToSalInt64( n ); break;
188 case SbxSALUINT64:
189 p->uInt64 = ImpDoubleToSalUInt64( n ); break;
190 case SbxDATE:
191 case SbxDOUBLE:
192 p->nDouble = n; break;
193
194 case SbxBYREF | SbxSTRING:
195 case SbxSTRING:
196 case SbxLPSTR:
197 if( !p->pOUString )
198 p->pOUString = new OUString;
199 // tdf#107953 - show 17 significant digits
200 ImpCvtNum( n, 17, *p->pOUString, bCoreString );
201 break;
202 case SbxOBJECT:
203 {
204 SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
205 if( pVal )
206 pVal->PutDouble( n );
207 else
209 break;
210 }
211 case SbxBYREF | SbxCHAR:
212 *p->pChar = ImpDoubleToChar(n); break;
213 case SbxBYREF | SbxBYTE:
214 *p->pByte = ImpDoubleToByte(n); break;
215 case SbxBYREF | SbxINTEGER:
216 case SbxBYREF | SbxBOOL:
217 *p->pInteger = ImpDoubleToInteger(n); break;
218 case SbxBYREF | SbxERROR:
219 case SbxBYREF | SbxUSHORT:
220 *p->pUShort = ImpDoubleToUShort(n); break;
221 case SbxBYREF | SbxLONG:
222 *p->pLong = ImpDoubleToLong(n); break;
223 case SbxBYREF | SbxULONG:
224 *p->pULong = ImpDoubleToULong(n); break;
225 case SbxBYREF | SbxSINGLE:
226 if( n > SbxMAXSNG )
227 {
229 }
230 else if( n < SbxMINSNG )
231 {
233 }
234 else if( n > 0 && n < SbxMAXSNG2 )
235 {
237 }
238 else if( n < 0 && n > SbxMINSNG2 )
239 {
241 }
242 *p->pSingle = static_cast<float>(n); break;
243 case SbxBYREF | SbxSALINT64:
244 *p->pnInt64 = ImpDoubleToSalInt64( n ); break;
245 case SbxBYREF | SbxSALUINT64:
246 *p->puInt64 = ImpDoubleToSalUInt64( n ); break;
247 case SbxBYREF | SbxDATE:
248 case SbxBYREF | SbxDOUBLE:
249 *p->pDouble = n; break;
250 case SbxBYREF | SbxCURRENCY:
251 if( n > SbxMAXCURR )
252 {
254 }
255 else if( n < SbxMINCURR )
256 {
258 }
259 *p->pnInt64 = ImpDoubleToCurrency( n ); break;
260
261 default:
263 }
264}
265
266/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XPropertyListType t
double d
static bool isVBAEnabled()
Definition: runtime.cxx:115
static void SetError(ErrCode)
Definition: sbxbase.cxx:116
bool setDouble(double val)
Definition: sbxdec.cxx:325
bool PutDouble(double)
double GetDouble() const
Definition: sbxvar.hxx:150
#define ERRCODE_NONE
void * p
sal_Int64 n
bool LibreOffice6FloatingPointMode()
Definition: methods1.cxx:2946
#define ERRCODE_BASIC_NO_OBJECT
Definition: sberrors.hxx:34
#define ERRCODE_BASIC_MATH_OVERFLOW
Definition: sberrors.hxx:27
#define ERRCODE_BASIC_CONVERSION
Definition: sberrors.hxx:30
double ImpCurrencyToDouble(const sal_Int64 r)
Definition: sbxconv.hxx:113
auto ImpDoubleToChar(double f)
Definition: sbxconv.hxx:50
auto ImpDoubleToInteger(double f)
Definition: sbxconv.hxx:53
auto ImpDoubleToSalUInt64(double d)
Definition: sbxconv.hxx:56
auto ImpDoubleToLong(double f)
Definition: sbxconv.hxx:55
auto ImpDoubleToUShort(double f)
Definition: sbxconv.hxx:52
auto ImpDoubleToULong(double f)
Definition: sbxconv.hxx:54
double ImpSalUInt64ToDouble(sal_uInt64 n)
Definition: sbxint.cxx:316
ErrCode ImpScan(const OUString &rSrc, double &nVal, SbxDataType &rType, sal_uInt16 *pLen, bool bOnlyIntntl)
Definition: sbxscan.cxx:71
sal_Int64 ImpDoubleToCurrency(double d)
Definition: sbxconv.hxx:105
auto ImpDoubleToSalInt64(double d)
Definition: sbxconv.hxx:57
SbxDecimal * ImpCreateDecimal(SbxValues *p)
Definition: sbxdec.cxx:376
auto ImpDoubleToByte(double f)
Definition: sbxconv.hxx:51
void ImpCvtNum(double nNum, short nPrec, OUString &rRes, bool bCoreString=false)
Definition: sbxscan.cxx:290
void ImpPutDouble(SbxValues *p, double n, bool bCoreString)
Definition: sbxdbl.cxx:138
double ImpGetDouble(const SbxValues *p)
Definition: sbxdbl.cxx:27
constexpr auto SbxMINSNG2
Definition: sbxdef.hxx:208
constexpr auto SbxMAXSNG2
Definition: sbxdef.hxx:207
constexpr auto SbxMINSNG
Definition: sbxdef.hxx:206
constexpr auto SbxMINCURR
Definition: sbxdef.hxx:203
SbxBOOL
Definition: sbxdef.hxx:215
constexpr auto SbxMAXCURR
Definition: sbxdef.hxx:202
SbxDataType
Definition: sbxdef.hxx:37
@ SbxOBJECT
Definition: sbxdef.hxx:47
@ SbxSALINT64
Definition: sbxdef.hxx:75
@ SbxLONG
Definition: sbxdef.hxx:41
@ SbxSALUINT64
Definition: sbxdef.hxx:76
@ SbxNULL
Definition: sbxdef.hxx:39
@ SbxBYTE
Definition: sbxdef.hxx:55
@ SbxEMPTY
Definition: sbxdef.hxx:38
@ SbxDECIMAL
Definition: sbxdef.hxx:77
@ SbxULONG
Definition: sbxdef.hxx:57
@ SbxUSHORT
Definition: sbxdef.hxx:56
@ SbxERROR
Definition: sbxdef.hxx:48
@ SbxDATE
Definition: sbxdef.hxx:45
@ SbxCURRENCY
Definition: sbxdef.hxx:44
@ SbxLPSTR
Definition: sbxdef.hxx:68
@ SbxSINGLE
Definition: sbxdef.hxx:42
@ SbxBYREF
Definition: sbxdef.hxx:81
@ SbxCHAR
Definition: sbxdef.hxx:54
@ SbxSTRING
Definition: sbxdef.hxx:46
@ SbxINTEGER
Definition: sbxdef.hxx:40
@ SbxDOUBLE
Definition: sbxdef.hxx:43
constexpr auto SbxMAXSNG
Definition: sbxdef.hxx:205
float * pSingle
Definition: sbxvar.hxx:72
sal_uInt8 * pByte
Definition: sbxvar.hxx:63
sal_uInt32 * pULong
Definition: sbxvar.hxx:67
sal_uInt16 * pUShort
Definition: sbxvar.hxx:64
sal_Int16 * pInteger
Definition: sbxvar.hxx:66
sal_Int32 * pLong
Definition: sbxvar.hxx:68
SbxDataType eType
Definition: sbxvar.hxx:77
sal_Unicode * pChar
Definition: sbxvar.hxx:65