1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
22 #include <o3tl/float_int_conversion.hxx>
23 #include <vcl/errcode.hxx>
24 #include <basic/sberrors.hxx>
25 #include "sbxconv.hxx"
27 #include <rtl/math.hxx>
29 sal_Int16
ImpGetInteger( const SbxValues
* p
)
37 SbxBase::SetError( ERRCODE_BASIC_CONVERSION
);
42 nRes
= p
->nChar
; break;
44 nRes
= p
->nByte
; break;
47 nRes
= p
->nInteger
; break;
50 if( p
->nUShort
> sal_uInt16(SbxMAXINT
) )
52 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); nRes
= SbxMAXINT
;
55 nRes
= static_cast<sal_Int16
>(p
->nUShort
);
58 if( p
->nLong
> SbxMAXINT
)
60 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); nRes
= SbxMAXINT
;
62 else if( p
->nLong
< SbxMININT
)
64 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); nRes
= SbxMININT
;
67 nRes
= static_cast<sal_Int16
>(p
->nLong
);
70 if( p
->nULong
> SbxMAXINT
)
72 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); nRes
= SbxMAXINT
;
75 nRes
= static_cast<sal_Int16
>(p
->nULong
);
78 if( !o3tl::convertsToAtMost(o3tl::roundAway(p
->nSingle
), SbxMAXINT
) )
80 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); nRes
= SbxMAXINT
;
82 else if( !o3tl::convertsToAtLeast(o3tl::roundAway(p
->nSingle
), SbxMININT
) )
84 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); nRes
= SbxMININT
;
87 nRes
= static_cast<sal_Int16
>(rtl::math::round( p
->nSingle
));
91 sal_Int64 tstVal
= p
->nInt64
/ sal_Int64(CURRENCY_FACTOR
);
93 if( tstVal
> SbxMAXINT
)
95 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); nRes
= SbxMAXINT
;
97 else if( tstVal
< SbxMININT
)
99 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); nRes
= SbxMININT
;
102 nRes
= static_cast<sal_Int16
>(tstVal
);
106 if( p
->nInt64
> SbxMAXINT
)
108 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); nRes
= SbxMAXINT
;
110 else if( p
->nInt64
< SbxMININT
)
112 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); nRes
= SbxMININT
;
115 nRes
= static_cast<sal_Int16
>(p
->nInt64
);
118 if( p
->uInt64
> SbxMAXINT
)
120 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); nRes
= SbxMAXINT
;
123 nRes
= static_cast<sal_Int16
>(p
->uInt64
);
128 case SbxBYREF
| SbxDECIMAL
:
131 if( p
->eType
== SbxDECIMAL
)
134 p
->pDecimal
->getDouble( dVal
);
139 if( !o3tl::convertsToAtMost(o3tl::roundAway(dVal
), SbxMAXINT
) )
141 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); nRes
= SbxMAXINT
;
143 else if( !o3tl::convertsToAtLeast(o3tl::roundAway(dVal
), SbxMININT
) )
145 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); nRes
= SbxMININT
;
148 nRes
= static_cast<sal_Int16
>(rtl::math::round( dVal
));
153 case SbxBYREF
| SbxSTRING
:
160 if( ImpScan( *p
->pOUString
, d
, t
, nullptr, false ) != ERRCODE_NONE
)
162 else if( !o3tl::convertsToAtMost(o3tl::roundAway(d
), SbxMAXINT
) )
164 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); nRes
= SbxMAXINT
;
166 else if( !o3tl::convertsToAtLeast(o3tl::roundAway(d
), SbxMININT
) )
168 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); nRes
= SbxMININT
;
171 nRes
= static_cast<sal_Int16
>(rtl::math::round( d
));
176 SbxValue
* pVal
= dynamic_cast<SbxValue
*>( p
->pObj
);
178 nRes
= pVal
->GetInteger();
181 SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT
); nRes
= 0;
186 case SbxBYREF
| SbxCHAR
:
187 nRes
= *p
->pChar
; break;
188 case SbxBYREF
| SbxBYTE
:
189 nRes
= *p
->pByte
; break;
190 case SbxBYREF
| SbxINTEGER
:
191 case SbxBYREF
| SbxBOOL
:
192 nRes
= *p
->pInteger
; break;
194 // from here had to be tested
195 case SbxBYREF
| SbxLONG
:
196 aTmp
.nLong
= *p
->pLong
; goto ref
;
197 case SbxBYREF
| SbxULONG
:
198 aTmp
.nULong
= *p
->pULong
; goto ref
;
199 case SbxBYREF
| SbxERROR
:
200 case SbxBYREF
| SbxUSHORT
:
201 aTmp
.nUShort
= *p
->pUShort
; goto ref
;
202 case SbxBYREF
| SbxSINGLE
:
203 aTmp
.nSingle
= *p
->pSingle
; goto ref
;
204 case SbxBYREF
| SbxDATE
:
205 case SbxBYREF
| SbxDOUBLE
:
206 aTmp
.nDouble
= *p
->pDouble
; goto ref
;
207 case SbxBYREF
| SbxCURRENCY
:
208 case SbxBYREF
| SbxSALINT64
:
209 aTmp
.nInt64
= *p
->pnInt64
; goto ref
;
210 case SbxBYREF
| SbxSALUINT64
:
211 aTmp
.uInt64
= *p
->puInt64
; goto ref
;
213 aTmp
.eType
= SbxDataType( p
->eType
& 0x0FFF );
214 p
= &aTmp
; goto start
;
217 SbxBase::SetError( ERRCODE_BASIC_CONVERSION
); nRes
= 0;
222 void ImpPutInteger( SbxValues
* p
, sal_Int16 n
)
228 // here had to be tested
230 aTmp
.pChar
= &p
->nChar
; goto direct
;
232 aTmp
.pByte
= &p
->nByte
; goto direct
;
234 aTmp
.pULong
= &p
->nULong
; goto direct
;
237 aTmp
.pUShort
= &p
->nUShort
; goto direct
;
239 aTmp
.puInt64
= &p
->uInt64
; goto direct
;
241 aTmp
.eType
= SbxDataType( p
->eType
| SbxBYREF
);
242 p
= &aTmp
; goto start
;
244 // from here no tests needed
247 p
->nInteger
= n
; break;
251 p
->nSingle
= n
; break;
254 p
->nDouble
= n
; break;
256 p
->nInt64
= n
* CURRENCY_FACTOR
; break;
258 p
->nInt64
= n
; break;
260 case SbxBYREF
| SbxDECIMAL
:
261 ImpCreateDecimal( p
)->setInt( n
);
266 case SbxBYREF
| SbxSTRING
:
268 p
->pOUString
= new OUString
;
269 ImpCvtNum( static_cast<double>(n
), 0, *p
->pOUString
);
273 SbxValue
* pVal
= dynamic_cast<SbxValue
*>( p
->pObj
);
275 pVal
->PutInteger( n
);
277 SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT
);
280 case SbxBYREF
| SbxCHAR
:
283 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); n
= SbxMINCHAR
;
285 *p
->pChar
= static_cast<char>(n
); break;
286 case SbxBYREF
| SbxBYTE
:
289 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); n
= SbxMAXBYTE
;
293 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); n
= 0;
295 *p
->pByte
= static_cast<sal_uInt8
>(n
); break;
296 case SbxBYREF
| SbxINTEGER
:
297 case SbxBYREF
| SbxBOOL
:
298 *p
->pInteger
= n
; break;
299 case SbxBYREF
| SbxERROR
:
300 case SbxBYREF
| SbxUSHORT
:
303 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); n
= 0;
305 *p
->pUShort
= static_cast<sal_uInt16
>(n
); break;
306 case SbxBYREF
| SbxLONG
:
307 *p
->pLong
= static_cast<sal_Int32
>(n
); break;
308 case SbxBYREF
| SbxULONG
:
311 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); n
= 0;
313 *p
->pULong
= static_cast<sal_uInt32
>(n
); break;
314 case SbxBYREF
| SbxCURRENCY
:
315 *p
->pnInt64
= n
* CURRENCY_FACTOR
; break;
316 case SbxBYREF
| SbxSALINT64
:
317 *p
->pnInt64
= n
; break;
318 case SbxBYREF
| SbxSALUINT64
:
321 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
);
327 case SbxBYREF
| SbxSINGLE
:
328 *p
->pSingle
= static_cast<float>(n
); break;
329 case SbxBYREF
| SbxDATE
:
330 case SbxBYREF
| SbxDOUBLE
:
331 *p
->pDouble
= static_cast<double>(n
); break;
334 SbxBase::SetError( ERRCODE_BASIC_CONVERSION
);
341 sal_Int64
ImpDoubleToSalInt64( double d
)
344 if( !o3tl::convertsToAtMost(o3tl::roundAway(d
), SAL_MAX_INT64
) )
346 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); nRes
= SAL_MAX_INT64
;
348 else if( !o3tl::convertsToAtLeast(o3tl::roundAway(d
), SAL_MIN_INT64
) )
350 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); nRes
= SAL_MIN_INT64
;
353 nRes
= static_cast<sal_Int64
>(rtl::math::round( d
));
357 sal_uInt64
ImpDoubleToSalUInt64( double d
)
360 if( !o3tl::convertsToAtMost(o3tl::roundAway(d
), SAL_MAX_UINT64
) )
362 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); nRes
= SAL_MAX_UINT64
;
366 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); nRes
= 0;
369 nRes
= static_cast<sal_uInt64
>(rtl::math::round( d
));
374 double ImpSalUInt64ToDouble( sal_uInt64 n
)
377 if( n
> SAL_MAX_INT64
)
378 SbxBase::SetError( ERRCODE_BASIC_CONVERSION
);
380 d
= static_cast<double>(static_cast<sal_Int64
>(n
));
385 sal_Int64
ImpGetInt64( const SbxValues
* p
)
393 SbxBase::SetError( ERRCODE_BASIC_CONVERSION
);
398 nRes
= p
->nChar
; break;
400 nRes
= p
->nByte
; break;
403 nRes
= p
->nInteger
; break;
406 nRes
= static_cast<sal_Int64
>(p
->nUShort
); break;
408 nRes
= static_cast<sal_Int64
>(p
->nLong
); break;
410 nRes
= static_cast<sal_Int64
>(p
->nULong
); break;
412 nRes
= static_cast<sal_Int64
>(p
->nSingle
);
416 nRes
= static_cast<sal_Int64
>(p
->nDouble
);
419 nRes
= p
->nInt64
/ CURRENCY_FACTOR
; break;
421 nRes
= p
->nInt64
; break;
423 if( p
->uInt64
> SAL_MAX_INT64
)
425 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); nRes
= SAL_MAX_INT64
;
428 nRes
= static_cast<sal_Int64
>(p
->uInt64
);
431 case SbxBYREF
| SbxSTRING
:
438 ::OString aOStr
= OUStringToOString( *p
->pOUString
, RTL_TEXTENCODING_ASCII_US
);
439 nRes
= aOStr
.toInt64();
442 // Check if really 0 or invalid conversion
445 if( ImpScan( *p
->pOUString
, d
, t
, nullptr, false ) != ERRCODE_NONE
)
448 nRes
= static_cast<sal_Int64
>(d
);
454 SbxValue
* pVal
= dynamic_cast<SbxValue
*>( p
->pObj
);
456 nRes
= pVal
->GetInt64();
459 SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT
); nRes
= 0;
464 case SbxBYREF
| SbxCHAR
:
465 nRes
= *p
->pChar
; break;
466 case SbxBYREF
| SbxBYTE
:
467 nRes
= *p
->pByte
; break;
468 case SbxBYREF
| SbxINTEGER
:
469 case SbxBYREF
| SbxBOOL
:
470 nRes
= *p
->pInteger
; break;
471 case SbxBYREF
| SbxLONG
:
472 nRes
= *p
->pLong
; break;
473 case SbxBYREF
| SbxULONG
:
474 nRes
= *p
->pULong
; break;
475 case SbxBYREF
| SbxCURRENCY
:
476 nRes
= p
->nInt64
/ CURRENCY_FACTOR
; break;
477 case SbxBYREF
| SbxSALINT64
:
478 nRes
= *p
->pnInt64
; break;
480 // from here the values has to be checked
481 case SbxBYREF
| SbxSALUINT64
:
482 aTmp
.uInt64
= *p
->puInt64
; goto ref
;
484 case SbxBYREF
| SbxERROR
:
485 case SbxBYREF
| SbxUSHORT
:
486 aTmp
.nUShort
= *p
->pUShort
; goto ref
;
487 case SbxBYREF
| SbxSINGLE
:
488 aTmp
.nSingle
= *p
->pSingle
; goto ref
;
489 case SbxBYREF
| SbxDATE
:
490 case SbxBYREF
| SbxDOUBLE
:
491 aTmp
.nDouble
= *p
->pDouble
; goto ref
;
493 aTmp
.eType
= SbxDataType( p
->eType
& 0x0FFF );
494 p
= &aTmp
; goto start
;
497 SbxBase::SetError( ERRCODE_BASIC_CONVERSION
); nRes
= 0;
502 void ImpPutInt64( SbxValues
* p
, sal_Int64 n
)
511 aTmp
.pChar
= &p
->nChar
; goto direct
;
513 aTmp
.pByte
= &p
->nByte
; goto direct
;
516 aTmp
.pInteger
= &p
->nInteger
; goto direct
;
518 aTmp
.pULong
= &p
->nULong
; goto direct
;
521 aTmp
.pUShort
= &p
->nUShort
; goto direct
;
523 aTmp
.pnInt64
= &p
->nInt64
; goto direct
;
526 aTmp
.pnInt64
= &p
->nInt64
; goto direct
;
528 aTmp
.puInt64
= &p
->uInt64
; goto direct
;
531 aTmp
.eType
= SbxDataType( p
->eType
| SbxBYREF
);
532 p
= &aTmp
; goto start
;
535 p
->nSingle
= static_cast<float>(n
); break;
538 p
->nDouble
= static_cast<double>(n
); break;
540 case SbxBYREF
| SbxSTRING
:
545 p
->pOUString
= new OUString
;
547 ::OString aOStr
= OString::number( n
);
548 (*p
->pOUString
) = ::OStringToOUString( aOStr
, RTL_TEXTENCODING_ASCII_US
);
553 SbxValue
* pVal
= dynamic_cast<SbxValue
*>( p
->pObj
);
557 SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT
);
560 case SbxBYREF
| SbxCHAR
:
563 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); n
= SbxMAXCHAR
;
565 else if( n
< SbxMINCHAR
)
567 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); n
= SbxMINCHAR
;
569 *p
->pChar
= static_cast<sal_Unicode
>(n
); break;
570 case SbxBYREF
| SbxBYTE
:
573 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); n
= SbxMAXBYTE
;
577 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); n
= 0;
579 *p
->pByte
= static_cast<sal_uInt8
>(n
); break;
580 case SbxBYREF
| SbxINTEGER
:
581 case SbxBYREF
| SbxBOOL
:
584 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); n
= SbxMAXINT
;
586 else if( n
< SbxMININT
)
588 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); n
= SbxMININT
;
590 *p
->pInteger
= static_cast<sal_Int16
>(n
); break;
591 case SbxBYREF
| SbxERROR
:
592 case SbxBYREF
| SbxUSHORT
:
595 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); n
= SbxMAXUINT
;
599 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); n
= 0;
601 *p
->pUShort
= static_cast<sal_uInt16
>(n
); break;
602 case SbxBYREF
| SbxLONG
:
605 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); n
= SbxMAXLNG
;
607 else if( n
< SbxMINLNG
)
609 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); n
= SbxMINLNG
;
611 *p
->pLong
= static_cast<sal_Int32
>(n
); break;
612 case SbxBYREF
| SbxULONG
:
615 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); n
= SbxMAXULNG
;
619 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); n
= 0;
621 *p
->pULong
= static_cast<sal_uInt32
>(n
); break;
622 case SbxBYREF
| SbxSINGLE
:
623 *p
->pSingle
= static_cast<float>(n
); break;
624 case SbxBYREF
| SbxDATE
:
625 case SbxBYREF
| SbxDOUBLE
:
626 *p
->pDouble
= static_cast<double>(n
); break;
627 case SbxBYREF
| SbxCURRENCY
:
628 *p
->pnInt64
= n
* CURRENCY_FACTOR
; break;
629 case SbxBYREF
| SbxSALINT64
:
630 *p
->pnInt64
= n
; break;
631 case SbxBYREF
| SbxSALUINT64
:
634 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); n
= 0;
636 *p
->puInt64
= n
; break;
639 SbxBase::SetError( ERRCODE_BASIC_CONVERSION
);
643 sal_uInt64
ImpGetUInt64( const SbxValues
* p
)
651 SbxBase::SetError( ERRCODE_BASIC_CONVERSION
);
656 nRes
= p
->nChar
; break;
658 nRes
= p
->nByte
; break;
661 nRes
= p
->nInteger
; break;
664 nRes
= p
->nUShort
; break;
666 nRes
= p
->nLong
; break;
668 nRes
= static_cast<sal_uInt64
>(p
->nULong
); break;
670 nRes
= static_cast<sal_uInt64
>(p
->nSingle
); break;
674 //TODO overflow check
675 nRes
= static_cast<sal_uInt64
>(p
->nDouble
);
679 nRes
= p
->nInt64
* CURRENCY_FACTOR
; break;
683 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); nRes
= 0;
686 nRes
= static_cast<sal_uInt64
>(p
->nInt64
);
689 nRes
= p
->uInt64
; break;
691 case SbxBYREF
| SbxSTRING
:
698 ::OString aOStr
= OUStringToOString
699 ( *p
->pOUString
, RTL_TEXTENCODING_ASCII_US
);
700 sal_Int64 n64
= aOStr
.toInt64();
703 // Check if really 0 or invalid conversion
706 if( ImpScan( *p
->pOUString
, d
, t
, nullptr, false ) != ERRCODE_NONE
)
708 else if( !o3tl::convertsToAtMost(o3tl::roundAway(d
), SAL_MAX_UINT64
) )
710 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); nRes
= SAL_MAX_UINT64
;
714 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); nRes
= 0;
717 nRes
= static_cast<sal_uInt64
>(rtl::math::round( d
));
721 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); nRes
= 0;
731 SbxValue
* pVal
= dynamic_cast<SbxValue
*>( p
->pObj
);
733 nRes
= pVal
->GetUInt64();
736 SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT
); nRes
= 0;
741 case SbxBYREF
| SbxCHAR
:
742 nRes
= *p
->pChar
; break;
743 case SbxBYREF
| SbxBYTE
:
744 nRes
= *p
->pByte
; break;
745 case SbxBYREF
| SbxINTEGER
:
746 case SbxBYREF
| SbxBOOL
:
747 nRes
= *p
->pInteger
; break;
748 case SbxBYREF
| SbxLONG
:
749 nRes
= *p
->pLong
; break;
750 case SbxBYREF
| SbxULONG
:
751 nRes
= *p
->pULong
; break;
752 case SbxBYREF
| SbxSALUINT64
:
753 nRes
= *p
->puInt64
; break;
755 // from here on the value has to be checked
756 case SbxBYREF
| SbxERROR
:
757 case SbxBYREF
| SbxUSHORT
:
758 aTmp
.nUShort
= *p
->pUShort
; goto ref
;
759 case SbxBYREF
| SbxSINGLE
:
760 aTmp
.nSingle
= *p
->pSingle
; goto ref
;
761 case SbxBYREF
| SbxDATE
:
762 case SbxBYREF
| SbxDOUBLE
:
763 aTmp
.nDouble
= *p
->pDouble
; goto ref
;
764 case SbxBYREF
| SbxCURRENCY
:
765 case SbxBYREF
| SbxSALINT64
:
766 aTmp
.nInt64
= *p
->pnInt64
; goto ref
;
768 aTmp
.eType
= SbxDataType( p
->eType
& 0x0FFF );
769 p
= &aTmp
; goto start
;
772 SbxBase::SetError( ERRCODE_BASIC_CONVERSION
); nRes
= 0;
777 void ImpPutUInt64( SbxValues
* p
, sal_uInt64 n
)
786 aTmp
.pChar
= &p
->nChar
; goto direct
;
788 aTmp
.pByte
= &p
->nByte
; goto direct
;
791 aTmp
.pInteger
= &p
->nInteger
; goto direct
;
793 aTmp
.pULong
= &p
->nULong
; goto direct
;
796 aTmp
.pUShort
= &p
->nUShort
; goto direct
;
798 aTmp
.pnInt64
= &p
->nInt64
; goto direct
;
801 aTmp
.pnInt64
= &p
->nInt64
; goto direct
;
803 aTmp
.pSingle
= &p
->nSingle
; goto direct
;
806 aTmp
.pDouble
= &p
->nDouble
; goto direct
;
809 aTmp
.eType
= SbxDataType( p
->eType
| SbxBYREF
);
810 p
= &aTmp
; goto start
;
812 // Check not necessary
814 p
->uInt64
= n
; break;
816 case SbxBYREF
| SbxSTRING
:
820 p
->pOUString
= new OUString
;
821 if( n
> SAL_MAX_INT64
)
822 SbxBase::SetError( ERRCODE_BASIC_CONVERSION
);
825 ::OString aOStr
= OString::number( n
);
826 (*p
->pOUString
) = ::OStringToOUString( aOStr
, RTL_TEXTENCODING_ASCII_US
);
831 SbxValue
* pVal
= dynamic_cast<SbxValue
*>( p
->pObj
);
833 pVal
->PutUInt64( n
);
835 SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT
);
838 case SbxBYREF
| SbxCHAR
:
841 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); n
= SbxMAXCHAR
;
843 *p
->pChar
= static_cast<sal_Unicode
>(n
); break;
844 case SbxBYREF
| SbxBYTE
:
847 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); n
= SbxMAXBYTE
;
849 *p
->pByte
= static_cast<sal_uInt8
>(n
); break;
850 case SbxBYREF
| SbxINTEGER
:
851 case SbxBYREF
| SbxBOOL
:
854 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); n
= SbxMAXINT
;
856 *p
->pInteger
= static_cast<sal_Int16
>(n
); break;
857 case SbxBYREF
| SbxERROR
:
858 case SbxBYREF
| SbxUSHORT
:
861 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); n
= SbxMAXUINT
;
863 *p
->pUShort
= static_cast<sal_uInt16
>(n
); break;
864 case SbxBYREF
| SbxLONG
:
867 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); n
= SbxMAXLNG
;
869 *p
->pLong
= static_cast<sal_Int32
>(n
); break;
870 case SbxBYREF
| SbxULONG
:
873 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); n
= SbxMAXULNG
;
875 *p
->pULong
= static_cast<sal_uInt32
>(n
); break;
876 case SbxBYREF
| SbxSINGLE
:
877 *p
->pDouble
= static_cast<float>(ImpSalUInt64ToDouble( n
)); break;
878 case SbxBYREF
| SbxDATE
:
879 case SbxBYREF
| SbxDOUBLE
:
881 *p
->pDouble
= ImpSalUInt64ToDouble( n
); break;
882 case SbxBYREF
| SbxCURRENCY
:
883 if ( n
> ( SAL_MAX_INT64
/ CURRENCY_FACTOR
) )
885 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
);
888 *p
->pnInt64
= static_cast<sal_Int64
>( n
* CURRENCY_FACTOR
); break;
889 case SbxBYREF
| SbxSALUINT64
:
890 *p
->puInt64
= n
; break;
891 case SbxBYREF
| SbxSALINT64
:
892 if( n
> SAL_MAX_INT64
)
894 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); n
= 0;
896 *p
->pnInt64
= static_cast<sal_Int64
>(n
); break;
899 SbxBase::SetError( ERRCODE_BASIC_CONVERSION
);
904 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */