1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sbxsng.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_basic.hxx"
33 #include <tools/errcode.hxx>
34 #include <basic/sbx.hxx>
35 #include "sbxconv.hxx"
37 float ImpGetSingle( const SbxValues
* p
)
45 SbxBase::SetError( SbxERR_CONVERSION
);
49 nRes
= p
->nChar
; break;
51 nRes
= p
->nByte
; break;
54 nRes
= p
->nInteger
; break;
57 nRes
= p
->nUShort
; break;
59 nRes
= (float) p
->nLong
; break;
61 nRes
= (float) p
->nULong
; break;
63 nRes
= p
->nSingle
; break;
65 nRes
= (float) p
->nInt64
; break;
67 nRes
= (float) ImpSalUInt64ToDouble( p
->uInt64
); break;
69 case SbxBYREF
| SbxDECIMAL
:
71 p
->pDecimal
->getSingle( nRes
);
82 if( p
->eType
== SbxCURRENCY
)
83 dVal
= ImpCurrencyToDouble( p
->nLong64
);
84 else if( p
->eType
== SbxLONG64
)
85 dVal
= ImpINT64ToDouble( p
->nLong64
);
86 else if( p
->eType
== SbxULONG64
)
87 dVal
= ImpUINT64ToDouble( p
->nULong64
);
91 if( dVal
> SbxMAXSNG
)
93 SbxBase::SetError( SbxERR_OVERFLOW
);
94 nRes
= static_cast< float >(SbxMAXSNG
);
96 else if( dVal
< SbxMINSNG
)
98 SbxBase::SetError( SbxERR_OVERFLOW
);
99 nRes
= static_cast< float >(SbxMINSNG
);
101 else if( dVal
> 0 && dVal
< SbxMAXSNG2
)
103 SbxBase::SetError( SbxERR_OVERFLOW
);
104 nRes
= static_cast< float >(SbxMAXSNG2
);
106 else if( dVal
< 0 && dVal
> SbxMINSNG2
)
108 SbxBase::SetError( SbxERR_OVERFLOW
);
109 nRes
= static_cast< float >(SbxMINSNG2
);
115 case SbxBYREF
| SbxSTRING
:
124 if( ImpScan( *p
->pString
, d
, t
, NULL
) != SbxERR_OK
)
126 else if( d
> SbxMAXSNG
)
128 SbxBase::SetError( SbxERR_OVERFLOW
);
129 nRes
= static_cast< float >(SbxMAXSNG
);
131 else if( d
< SbxMINSNG
)
133 SbxBase::SetError( SbxERR_OVERFLOW
);
134 nRes
= static_cast< float >(SbxMINSNG
);
142 SbxValue
* pVal
= PTR_CAST(SbxValue
,p
->pObj
);
144 nRes
= pVal
->GetSingle();
147 SbxBase::SetError( SbxERR_NO_OBJECT
); nRes
= 0;
152 case SbxBYREF
| SbxCHAR
:
153 nRes
= *p
->pChar
; break;
154 case SbxBYREF
| SbxBYTE
:
155 nRes
= *p
->pByte
; break;
156 case SbxBYREF
| SbxINTEGER
:
157 case SbxBYREF
| SbxBOOL
:
158 nRes
= *p
->pInteger
; break;
159 case SbxBYREF
| SbxLONG
:
160 nRes
= (float) *p
->pLong
; break;
161 case SbxBYREF
| SbxULONG
:
162 nRes
= (float) *p
->pULong
; break;
163 case SbxBYREF
| SbxERROR
:
164 case SbxBYREF
| SbxUSHORT
:
165 nRes
= *p
->pUShort
; break;
166 case SbxBYREF
| SbxSINGLE
:
167 nRes
= *p
->pSingle
; break;
168 // ab hier muss getestet werden
169 case SbxBYREF
| SbxDATE
:
170 case SbxBYREF
| SbxDOUBLE
:
171 aTmp
.nDouble
= *p
->pDouble
; goto ref
;
172 case SbxBYREF
| SbxULONG64
:
173 aTmp
.nULong64
= *p
->pULong64
; goto ref
;
174 case SbxBYREF
| SbxLONG64
:
175 case SbxBYREF
| SbxSALINT64
:
176 nRes
= (float) *p
->pnInt64
; break;
177 case SbxBYREF
| SbxSALUINT64
:
178 nRes
= (float) ImpSalUInt64ToDouble( *p
->puInt64
); break;
179 case SbxBYREF
| SbxCURRENCY
:
180 aTmp
.nLong64
= *p
->pLong64
; goto ref
;
182 aTmp
.eType
= SbxDataType( p
->eType
& 0x0FFF );
183 p
= &aTmp
; goto start
;
186 SbxBase::SetError( SbxERR_CONVERSION
); nRes
= 0;
191 void ImpPutSingle( SbxValues
* p
, float n
)
198 aTmp
.pChar
= &p
->nChar
; goto direct
;
200 aTmp
.pByte
= &p
->nByte
; goto direct
;
203 aTmp
.pInteger
= &p
->nInteger
; goto direct
;
205 aTmp
.pLong
= &p
->nLong
; goto direct
;
207 aTmp
.pULong
= &p
->nULong
; goto direct
;
210 aTmp
.pUShort
= &p
->nUShort
; goto direct
;
212 aTmp
.pULong64
= &p
->nULong64
; goto direct
;
215 aTmp
.pLong64
= &p
->nLong64
; goto direct
;
217 aTmp
.pnInt64
= &p
->nInt64
; goto direct
;
219 aTmp
.puInt64
= &p
->uInt64
; goto direct
;
221 case SbxBYREF
| SbxDECIMAL
:
223 SbxDecimal
* pDec
= ImpCreateDecimal( p
);
224 if( !pDec
->setSingle( n
) )
225 SbxBase::SetError( SbxERR_OVERFLOW
);
229 aTmp
.eType
= SbxDataType( p
->eType
| SbxBYREF
);
230 p
= &aTmp
; goto start
;
232 // keine Tests ab hier
234 p
->nSingle
= n
; break;
237 p
->nDouble
= n
; break;
239 case SbxBYREF
| SbxSTRING
:
244 p
->pString
= new XubString
;
245 ImpCvtNum( (double) n
, 6, *p
->pString
);
250 SbxValue
* pVal
= PTR_CAST(SbxValue
,p
->pObj
);
252 pVal
->PutSingle( n
);
254 SbxBase::SetError( SbxERR_NO_OBJECT
);
257 case SbxBYREF
| SbxCHAR
:
260 SbxBase::SetError( SbxERR_OVERFLOW
); n
= SbxMAXCHAR
;
262 else if( n
< SbxMINCHAR
)
264 SbxBase::SetError( SbxERR_OVERFLOW
); n
= SbxMINCHAR
;
266 *p
->pChar
= (xub_Unicode
) n
; break;
267 case SbxBYREF
| SbxBYTE
:
270 SbxBase::SetError( SbxERR_OVERFLOW
); n
= SbxMAXBYTE
;
274 SbxBase::SetError( SbxERR_OVERFLOW
); n
= 0;
276 *p
->pByte
= (BYTE
) n
; break;
277 case SbxBYREF
| SbxINTEGER
:
278 case SbxBYREF
| SbxBOOL
:
281 SbxBase::SetError( SbxERR_OVERFLOW
); n
= SbxMAXINT
;
283 else if( n
< SbxMININT
)
285 SbxBase::SetError( SbxERR_OVERFLOW
); n
= SbxMININT
;
287 *p
->pInteger
= (INT16
) n
; break;
288 case SbxBYREF
| SbxERROR
:
289 case SbxBYREF
| SbxUSHORT
:
292 SbxBase::SetError( SbxERR_OVERFLOW
); n
= SbxMAXUINT
;
296 SbxBase::SetError( SbxERR_OVERFLOW
); n
= 0;
298 *p
->pUShort
= (UINT16
) n
; break;
299 case SbxBYREF
| SbxLONG
:
304 SbxBase::SetError( SbxERR_OVERFLOW
); i
= SbxMAXLNG
;
306 else if( n
< SbxMINLNG
)
308 SbxBase::SetError( SbxERR_OVERFLOW
); i
= SbxMINLNG
;
312 i
= sal::static_int_cast
< INT32
>(n
);
314 *p
->pLong
= i
; break;
316 case SbxBYREF
| SbxULONG
:
321 SbxBase::SetError( SbxERR_OVERFLOW
); i
= SbxMAXULNG
;
325 SbxBase::SetError( SbxERR_OVERFLOW
); i
= 0;
329 i
= sal::static_int_cast
< UINT32
>(n
);
331 *p
->pULong
= i
; break;
333 case SbxBYREF
| SbxSINGLE
:
334 *p
->pSingle
= n
; break;
335 case SbxBYREF
| SbxDATE
:
336 case SbxBYREF
| SbxDOUBLE
:
337 *p
->pDouble
= (double) n
; break;
338 case SbxBYREF
| SbxSALINT64
:
339 *p
->pnInt64
= ImpDoubleToSalInt64( (double) n
); break;
340 case SbxBYREF
| SbxSALUINT64
:
341 *p
->puInt64
= ImpDoubleToSalUInt64( (double) n
); break;
342 case SbxBYREF
| SbxCURRENCY
:
346 SbxBase::SetError( SbxERR_OVERFLOW
); d
= SbxMAXCURR
;
348 else if( n
< SbxMINCURR
)
350 SbxBase::SetError( SbxERR_OVERFLOW
); d
= SbxMINCURR
;
356 *p
->pLong64
= ImpDoubleToCurrency( n
); break;
359 SbxBase::SetError( SbxERR_CONVERSION
);