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_basic.hxx" 26 27 #define _TLBIGINT_INT64 28 #include <tools/bigint.hxx> 29 #include <basic/sbx.hxx> 30 31 ///////////////////////////// BigInt/Currency ////////////////////////////// 32 SbxValues(const BigInt & rBig)33SbxValues::SbxValues( const BigInt &rBig ) : eType(SbxCURRENCY) 34 { 35 rBig.INT64( &nLong64 ); 36 } 37 38 //TODO: BigInt is TOOLS_DLLPUBLIC, and its four member functions only declared 39 // and defined within basic (#define _TLBIGINT_INT64) are a bad hack that causes 40 // "warning C4273: 'function' : inconsistent dll linkage" on MSC; this whole 41 // mess should be cleaned up properly (e.g., by completely removing Sbx[U]INT64 42 // and using sal_[u]Int64 instead): 43 #if defined _MSC_VER 44 #pragma warning(disable: 4273) 45 #endif 46 INT64(SbxINT64 * p) const47sal_Bool BigInt::INT64( SbxINT64 *p ) const 48 { 49 if( bIsBig ) { 50 if( nLen > 4 || (nNum[3] & 0x8000) ) 51 return sal_False; 52 53 p->nLow = ((sal_uInt32)nNum[1] << 16) | (sal_uInt32)nNum[0]; 54 p->nHigh = ((sal_uInt32)nNum[3] << 16) | (sal_uInt32)nNum[2]; 55 if( bIsNeg ) 56 p->CHS(); 57 } 58 else 59 p->Set( (sal_Int32)nVal ); 60 61 return sal_True; 62 } 63 BigInt(const SbxINT64 & r)64BigInt::BigInt( const SbxINT64 &r ) 65 { 66 BigInt a10000 = 0x10000; 67 68 *this = r.nHigh; 69 if( r.nHigh ) 70 *this *= a10000; 71 *this += (sal_uInt16)(r.nLow >> 16); 72 *this *= a10000; 73 *this += (sal_uInt16)r.nLow; 74 } 75 UINT64(SbxUINT64 * p) const76sal_Bool BigInt::UINT64( SbxUINT64 *p ) const 77 { 78 if( bIsBig ) { 79 if( bIsNeg || nLen > 4 ) 80 return sal_False; 81 82 p->nLow = ((sal_uInt32)nNum[1] << 16) | (sal_uInt32)nNum[0]; 83 p->nHigh = ((sal_uInt32)nNum[3] << 16) | (sal_uInt32)nNum[2]; 84 } 85 else { 86 if( nVal < 0 ) 87 return sal_False; 88 89 p->Set( (sal_uInt32)nVal ); 90 } 91 92 return sal_True; 93 } 94 BigInt(const SbxUINT64 & r)95BigInt::BigInt( const SbxUINT64 &r ) 96 { 97 BigInt a10000 = 0x10000; 98 99 *this = BigInt(r.nHigh); 100 if( r.nHigh ) 101 *this *= a10000; 102 *this += (sal_uInt16)(r.nLow >> 16); 103 *this *= a10000; 104 *this += (sal_uInt16)r.nLow; 105 } 106