Branch data Line data Source code
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 <com/sun/star/util/XNumberFormatTypes.hpp>
21 : :
22 : : #include <string.h>
23 : : #include <stdio.h>
24 : : #include <tools/resary.hxx>
25 : : #include <rtl/math.hxx>
26 : : #include <sal/macros.h>
27 : : #include "analysishelper.hxx"
28 : : #include "analysis.hrc"
29 : :
30 : : using namespace ::rtl;
31 : : using namespace ::com::sun::star;
32 : :
33 : :
34 : :
35 : : #define UNIQUE sal_False // function name does not exist in Calc
36 : : #define DOUBLE sal_True // function name exists in Calc
37 : :
38 : : #define STDPAR sal_False // all parameters are described
39 : : #define INTPAR sal_True // first parameter is internal
40 : :
41 : : #define FUNCDATA( FUNCNAME, DBL, OPT, NUMOFPAR, CAT ) \
42 : : { "get" #FUNCNAME, ANALYSIS_FUNCNAME_##FUNCNAME, ANALYSIS_##FUNCNAME, DBL, OPT, ANALYSIS_DEFFUNCNAME_##FUNCNAME, NUMOFPAR, CAT }
43 : :
44 : : const FuncDataBase pFuncDatas[] =
45 : : {
46 : : // UNIQUE or INTPAR or
47 : : // function name DOUBLE STDPAR # of param category
48 : : FUNCDATA( Workday, UNIQUE, INTPAR, 3, FDCat_DateTime ),
49 : : FUNCDATA( Yearfrac, UNIQUE, INTPAR, 3, FDCat_DateTime ),
50 : : FUNCDATA( Edate, UNIQUE, INTPAR, 2, FDCat_DateTime ),
51 : : FUNCDATA( Weeknum, DOUBLE, INTPAR, 2, FDCat_DateTime ),
52 : : FUNCDATA( Eomonth, UNIQUE, INTPAR, 2, FDCat_DateTime ),
53 : : FUNCDATA( Networkdays, UNIQUE, INTPAR, 3, FDCat_DateTime ),
54 : : FUNCDATA( Iseven, DOUBLE, STDPAR, 1, FDCat_Inf ),
55 : : FUNCDATA( Isodd, DOUBLE, STDPAR, 1, FDCat_Inf ),
56 : : FUNCDATA( Multinomial, UNIQUE, STDPAR, 1, FDCat_Math ),
57 : : FUNCDATA( Seriessum, UNIQUE, STDPAR, 4, FDCat_Math ),
58 : : FUNCDATA( Quotient, UNIQUE, STDPAR, 2, FDCat_Math ),
59 : : FUNCDATA( Mround, UNIQUE, STDPAR, 2, FDCat_Math ),
60 : : FUNCDATA( Sqrtpi, UNIQUE, STDPAR, 1, FDCat_Math ),
61 : : FUNCDATA( Randbetween, UNIQUE, STDPAR, 2, FDCat_Math ),
62 : : FUNCDATA( Gcd, DOUBLE, INTPAR, 1, FDCat_Math ),
63 : : FUNCDATA( Lcm, DOUBLE, INTPAR, 1, FDCat_Math ),
64 : : FUNCDATA( Besseli, UNIQUE, STDPAR, 2, FDCat_Tech ),
65 : : FUNCDATA( Besselj, UNIQUE, STDPAR, 2, FDCat_Tech ),
66 : : FUNCDATA( Besselk, UNIQUE, STDPAR, 2, FDCat_Tech ),
67 : : FUNCDATA( Bessely, UNIQUE, STDPAR, 2, FDCat_Tech ),
68 : : FUNCDATA( Bin2Oct, UNIQUE, INTPAR, 2, FDCat_Tech ),
69 : : FUNCDATA( Bin2Dec, UNIQUE, STDPAR, 1, FDCat_Tech ),
70 : : FUNCDATA( Bin2Hex, UNIQUE, INTPAR, 2, FDCat_Tech ),
71 : : FUNCDATA( Oct2Bin, UNIQUE, INTPAR, 2, FDCat_Tech ),
72 : : FUNCDATA( Oct2Dec, UNIQUE, STDPAR, 1, FDCat_Tech ),
73 : : FUNCDATA( Oct2Hex, UNIQUE, INTPAR, 2, FDCat_Tech ),
74 : : FUNCDATA( Dec2Bin, UNIQUE, INTPAR, 2, FDCat_Tech ),
75 : : FUNCDATA( Dec2Hex, UNIQUE, INTPAR, 2, FDCat_Tech ),
76 : : FUNCDATA( Dec2Oct, UNIQUE, INTPAR, 2, FDCat_Tech ),
77 : : FUNCDATA( Hex2Bin, UNIQUE, INTPAR, 2, FDCat_Tech ),
78 : : FUNCDATA( Hex2Dec, UNIQUE, STDPAR, 1, FDCat_Tech ),
79 : : FUNCDATA( Hex2Oct, UNIQUE, INTPAR, 2, FDCat_Tech ),
80 : : FUNCDATA( Delta, UNIQUE, INTPAR, 2, FDCat_Tech ),
81 : : FUNCDATA( Erf, UNIQUE, INTPAR, 2, FDCat_Tech ),
82 : : FUNCDATA( Erfc, UNIQUE, STDPAR, 1, FDCat_Tech ),
83 : : FUNCDATA( Gestep, UNIQUE, INTPAR, 2, FDCat_Tech ),
84 : : FUNCDATA( Factdouble, UNIQUE, STDPAR, 1, FDCat_Tech ),
85 : : FUNCDATA( Imabs, UNIQUE, STDPAR, 1, FDCat_Tech ),
86 : : FUNCDATA( Imaginary, UNIQUE, STDPAR, 1, FDCat_Tech ),
87 : : FUNCDATA( Impower, UNIQUE, STDPAR, 2, FDCat_Tech ),
88 : : FUNCDATA( Imargument, UNIQUE, STDPAR, 1, FDCat_Tech ),
89 : : FUNCDATA( Imcos, UNIQUE, STDPAR, 1, FDCat_Tech ),
90 : : FUNCDATA( Imdiv, UNIQUE, STDPAR, 2, FDCat_Tech ),
91 : : FUNCDATA( Imexp, UNIQUE, STDPAR, 1, FDCat_Tech ),
92 : : FUNCDATA( Imconjugate, UNIQUE, STDPAR, 1, FDCat_Tech ),
93 : : FUNCDATA( Imln, UNIQUE, STDPAR, 1, FDCat_Tech ),
94 : : FUNCDATA( Imlog10, UNIQUE, STDPAR, 1, FDCat_Tech ),
95 : : FUNCDATA( Imlog2, UNIQUE, STDPAR, 1, FDCat_Tech ),
96 : : FUNCDATA( Improduct, UNIQUE, INTPAR, 2, FDCat_Tech ),
97 : : FUNCDATA( Imreal, UNIQUE, STDPAR, 1, FDCat_Tech ),
98 : : FUNCDATA( Imsin, UNIQUE, STDPAR, 1, FDCat_Tech ),
99 : : FUNCDATA( Imsub, UNIQUE, STDPAR, 2, FDCat_Tech ),
100 : : FUNCDATA( Imsqrt, UNIQUE, STDPAR, 1, FDCat_Tech ),
101 : : FUNCDATA( Imsum, UNIQUE, INTPAR, 1, FDCat_Tech ),
102 : : FUNCDATA( Imtan, UNIQUE, STDPAR, 1, FDCat_Tech ),
103 : : FUNCDATA( Imsec, UNIQUE, STDPAR, 1, FDCat_Tech ),
104 : : FUNCDATA( Imcsc, UNIQUE, STDPAR, 1, FDCat_Tech ),
105 : : FUNCDATA( Imcot, UNIQUE, STDPAR, 1, FDCat_Tech ),
106 : : FUNCDATA( Imsinh, UNIQUE, STDPAR, 1, FDCat_Tech ),
107 : : FUNCDATA( Imcosh, UNIQUE, STDPAR, 1, FDCat_Tech ),
108 : : FUNCDATA( Imsech, UNIQUE, STDPAR, 1, FDCat_Tech ),
109 : : FUNCDATA( Imcsch, UNIQUE, STDPAR, 1, FDCat_Tech ),
110 : : FUNCDATA( Complex, UNIQUE, STDPAR, 3, FDCat_Tech ),
111 : : FUNCDATA( Convert, DOUBLE, STDPAR, 3, FDCat_Tech ),
112 : : FUNCDATA( Amordegrc, UNIQUE, INTPAR, 7, FDCat_Finance ),
113 : : FUNCDATA( Amorlinc, UNIQUE, INTPAR, 7, FDCat_Finance ),
114 : : FUNCDATA( Accrint, UNIQUE, INTPAR, 7, FDCat_Finance ),
115 : : FUNCDATA( Accrintm, UNIQUE, INTPAR, 5, FDCat_Finance ),
116 : : FUNCDATA( Received, UNIQUE, INTPAR, 5, FDCat_Finance ),
117 : : FUNCDATA( Disc, UNIQUE, INTPAR, 5, FDCat_Finance ),
118 : : FUNCDATA( Duration, DOUBLE, INTPAR, 6, FDCat_Finance ),
119 : : FUNCDATA( Effect, DOUBLE, STDPAR, 2, FDCat_Finance ),
120 : : FUNCDATA( Cumprinc, DOUBLE, STDPAR, 6, FDCat_Finance ),
121 : : FUNCDATA( Cumipmt, DOUBLE, STDPAR, 6, FDCat_Finance ),
122 : : FUNCDATA( Price, UNIQUE, INTPAR, 7, FDCat_Finance ),
123 : : FUNCDATA( Pricedisc, UNIQUE, INTPAR, 5, FDCat_Finance ),
124 : : FUNCDATA( Pricemat, UNIQUE, INTPAR, 6, FDCat_Finance ),
125 : : FUNCDATA( Mduration, UNIQUE, INTPAR, 6, FDCat_Finance ),
126 : : FUNCDATA( Nominal, DOUBLE, STDPAR, 2, FDCat_Finance ),
127 : : FUNCDATA( Dollarfr, UNIQUE, STDPAR, 2, FDCat_Finance ),
128 : : FUNCDATA( Dollarde, UNIQUE, STDPAR, 2, FDCat_Finance ),
129 : : FUNCDATA( Yield, UNIQUE, INTPAR, 7, FDCat_Finance ),
130 : : FUNCDATA( Yielddisc, UNIQUE, INTPAR, 5, FDCat_Finance ),
131 : : FUNCDATA( Yieldmat, UNIQUE, INTPAR, 6, FDCat_Finance ),
132 : : FUNCDATA( Tbilleq, UNIQUE, INTPAR, 3, FDCat_Finance ),
133 : : FUNCDATA( Tbillprice, UNIQUE, INTPAR, 3, FDCat_Finance ),
134 : : FUNCDATA( Tbillyield, UNIQUE, INTPAR, 3, FDCat_Finance ),
135 : : FUNCDATA( Oddfprice, UNIQUE, INTPAR, 9, FDCat_Finance ),
136 : : FUNCDATA( Oddfyield, UNIQUE, INTPAR, 9, FDCat_Finance ),
137 : : FUNCDATA( Oddlprice, UNIQUE, INTPAR, 8, FDCat_Finance ),
138 : : FUNCDATA( Oddlyield, UNIQUE, INTPAR, 8, FDCat_Finance ),
139 : : FUNCDATA( Xirr, UNIQUE, INTPAR, 3, FDCat_Finance ),
140 : : FUNCDATA( Xnpv, UNIQUE, STDPAR, 3, FDCat_Finance ),
141 : : FUNCDATA( Intrate, UNIQUE, INTPAR, 5, FDCat_Finance ),
142 : : FUNCDATA( Coupncd, UNIQUE, INTPAR, 4, FDCat_Finance ),
143 : : FUNCDATA( Coupdays, UNIQUE, INTPAR, 4, FDCat_Finance ),
144 : : FUNCDATA( Coupdaysnc, UNIQUE, INTPAR, 4, FDCat_Finance ),
145 : : FUNCDATA( Coupdaybs, UNIQUE, INTPAR, 4, FDCat_Finance ),
146 : : FUNCDATA( Couppcd, UNIQUE, INTPAR, 4, FDCat_Finance ),
147 : : FUNCDATA( Coupnum, UNIQUE, INTPAR, 4, FDCat_Finance ),
148 : : FUNCDATA( Fvschedule, UNIQUE, STDPAR, 2, FDCat_Finance )
149 : : };
150 : : #undef FUNCDATA
151 : :
152 : :
153 : 0 : sal_uInt16 DaysInMonth( sal_uInt16 nMonth, sal_uInt16 nYear )
154 : : {
155 [ # # ][ # # ]: 0 : if( (nMonth == 2) && IsLeapYear( nYear ) )
[ # # ]
156 : 0 : return 29;
157 : : static const sal_uInt16 aDaysInMonth[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
158 : 0 : return aDaysInMonth[ nMonth ];
159 : : }
160 : :
161 : :
162 : : /**
163 : : * Convert a date to a count of days starting from 01/01/0001
164 : : *
165 : : * The internal representation of a Date used in this Addin
166 : : * is the number of days between 01/01/0001 and the date
167 : : * this function converts a Day , Month, Year representation
168 : : * to this internal Date value.
169 : : *
170 : : */
171 : :
172 : 0 : sal_Int32 DateToDays( sal_uInt16 nDay, sal_uInt16 nMonth, sal_uInt16 nYear )
173 : : {
174 : 0 : sal_Int32 nDays = ((sal_Int32)nYear-1) * 365;
175 : 0 : nDays += ((nYear-1) / 4) - ((nYear-1) / 100) + ((nYear-1) / 400);
176 : :
177 [ # # ]: 0 : for( sal_uInt16 i = 1; i < nMonth; i++ )
178 : 0 : nDays += DaysInMonth(i,nYear);
179 : 0 : nDays += nDay;
180 : :
181 : 0 : return nDays;
182 : : }
183 : :
184 : :
185 : : /**
186 : : * Convert a count of days starting from 01/01/0001 to a date
187 : : *
188 : : * The internal representation of a Date used in this Addin
189 : : * is the number of days between 01/01/0001 and the date
190 : : * this function converts this internal Date value
191 : : * to a Day , Month, Year representation of a Date.
192 : : *
193 : : */
194 : :
195 : 0 : void DaysToDate( sal_Int32 nDays, sal_uInt16& rDay, sal_uInt16& rMonth, sal_uInt16& rYear )
196 : : throw( lang::IllegalArgumentException )
197 : : {
198 [ # # ]: 0 : if( nDays < 0 )
199 [ # # ]: 0 : throw lang::IllegalArgumentException();
200 : :
201 : : sal_Int32 nTempDays;
202 : 0 : sal_Int32 i = 0;
203 : : sal_Bool bCalc;
204 : :
205 [ # # ]: 0 : do
206 : : {
207 : 0 : nTempDays = nDays;
208 : 0 : rYear = (sal_uInt16)((nTempDays / 365) - i);
209 : 0 : nTempDays -= ((sal_Int32) rYear -1) * 365;
210 : 0 : nTempDays -= (( rYear -1) / 4) - (( rYear -1) / 100) + ((rYear -1) / 400);
211 : 0 : bCalc = sal_False;
212 [ # # ]: 0 : if ( nTempDays < 1 )
213 : : {
214 : 0 : i++;
215 : 0 : bCalc = sal_True;
216 : : }
217 : : else
218 : : {
219 [ # # ]: 0 : if ( nTempDays > 365 )
220 : : {
221 [ # # ][ # # ]: 0 : if ( (nTempDays != 366) || !IsLeapYear( rYear ) )
[ # # ]
222 : : {
223 : 0 : i--;
224 : 0 : bCalc = sal_True;
225 : : }
226 : : }
227 : : }
228 : : }
229 : : while ( bCalc );
230 : :
231 : 0 : rMonth = 1;
232 [ # # ]: 0 : while ( (sal_Int32)nTempDays > DaysInMonth( rMonth, rYear ) )
233 : : {
234 : 0 : nTempDays -= DaysInMonth( rMonth, rYear );
235 : 0 : rMonth++;
236 : : }
237 : 0 : rDay = (sal_uInt16)nTempDays;
238 : 0 : }
239 : :
240 : :
241 : : /**
242 : : * Get the null date used by the spreadsheet document
243 : : *
244 : : * The internal representation of a Date used in this Addin
245 : : * is the number of days between 01/01/0001 and the date
246 : : * this function returns this internal Date value for the document null date
247 : : *
248 : : */
249 : :
250 : 0 : sal_Int32 GetNullDate( constREFXPS& xOpt ) THROWDEF_RTE
251 : : {
252 [ # # ]: 0 : if( xOpt.is() )
253 : : {
254 : : try
255 : : {
256 [ # # ][ # # ]: 0 : ANY aAny = xOpt->getPropertyValue( STRFROMASCII( "NullDate" ) );
257 : 0 : util::Date aDate;
258 [ # # ][ # # ]: 0 : if( aAny >>= aDate )
259 [ # # ][ # # ]: 0 : return DateToDays( aDate.Day, aDate.Month, aDate.Year );
260 : : }
261 : 0 : catch( uno::Exception& )
262 : : {
263 : : }
264 : : }
265 : :
266 : : // no null date available -> no calculations possible
267 [ # # ]: 0 : throw uno::RuntimeException();
268 : : }
269 : :
270 : :
271 : 0 : sal_Int32 GetDiffDate360(
272 : : sal_uInt16 nDay1, sal_uInt16 nMonth1, sal_uInt16 nYear1, sal_Bool bLeapYear1,
273 : : sal_uInt16 nDay2, sal_uInt16 nMonth2, sal_uInt16 nYear2,
274 : : sal_Bool bUSAMethod )
275 : : {
276 [ # # ]: 0 : if( nDay1 == 31 )
277 : 0 : nDay1--;
278 [ # # ][ # # ]: 0 : else if( bUSAMethod && ( nMonth1 == 2 && ( nDay1 == 29 || ( nDay1 == 28 && !bLeapYear1 ) ) ) )
[ # # ][ # # ]
[ # # ]
279 : 0 : nDay1 = 30;
280 : :
281 [ # # ]: 0 : if( nDay2 == 31 )
282 : : {
283 [ # # ][ # # ]: 0 : if( bUSAMethod && nDay1 != 30 )
284 : : {
285 : 0 : nDay2 = 1;
286 [ # # ]: 0 : if( nMonth2 == 12 )
287 : : {
288 : 0 : nYear2++;
289 : 0 : nMonth2 = 1;
290 : : }
291 : : else
292 : 0 : nMonth2++;
293 : : }
294 : : else
295 : 0 : nDay2 = 30;
296 : : }
297 : :
298 : 0 : return nDay2 + nMonth2 * 30 + nYear2 * 360 - nDay1 - nMonth1 * 30 - nYear1 * 360;
299 : : }
300 : :
301 : :
302 : 0 : sal_Int32 GetDiffDate360( sal_Int32 nNullDate, sal_Int32 nDate1, sal_Int32 nDate2, sal_Bool bUSAMethod )
303 : : {
304 : 0 : nDate1 += nNullDate;
305 : 0 : nDate2 += nNullDate;
306 : :
307 : : sal_uInt16 nDay1, nMonth1, nYear1, nDay2, nMonth2, nYear2;
308 : :
309 [ # # ]: 0 : DaysToDate( nDate1, nDay1, nMonth1, nYear1 );
310 [ # # ]: 0 : DaysToDate( nDate2, nDay2, nMonth2, nYear2 );
311 : :
312 : 0 : return GetDiffDate360( nDay1, nMonth1, nYear1, IsLeapYear( nYear1 ), nDay2, nMonth2, nYear2, bUSAMethod );
313 : : }
314 : :
315 : :
316 : 0 : sal_Int32 GetDaysInYears( sal_uInt16 nYear1, sal_uInt16 nYear2 )
317 : : {
318 : 0 : sal_uInt16 nLeaps = 0;
319 [ # # ]: 0 : for( sal_uInt16 n = nYear1 ; n <= nYear2 ; n++ )
320 : : {
321 [ # # ]: 0 : if( IsLeapYear( n ) )
322 : 0 : nLeaps++;
323 : : }
324 : :
325 : 0 : sal_uInt32 nSum = 1;
326 : 0 : nSum += nYear2;
327 : 0 : nSum -= nYear1;
328 : 0 : nSum *= 365;
329 : 0 : nSum += nLeaps;
330 : :
331 : 0 : return nSum;
332 : : }
333 : :
334 : :
335 : 0 : void GetDiffParam( sal_Int32 nNullDate, sal_Int32 nStartDate, sal_Int32 nEndDate, sal_Int32 nMode,
336 : : sal_uInt16& rYears, sal_Int32& rDayDiffPart, sal_Int32& rDaysInYear ) THROWDEF_RTE_IAE
337 : : {
338 [ # # ]: 0 : if( nStartDate > nEndDate )
339 : : {
340 : 0 : sal_Int32 n = nEndDate;
341 : 0 : nEndDate = nStartDate;
342 : 0 : nStartDate = n;
343 : : }
344 : :
345 : 0 : sal_Int32 nDate1 = nStartDate + nNullDate;
346 : 0 : sal_Int32 nDate2 = nEndDate + nNullDate;
347 : :
348 : : sal_uInt16 nDay1, nDay2;
349 : : sal_uInt16 nMonth1, nMonth2;
350 : : sal_uInt16 nYear1, nYear2;
351 : :
352 [ # # ]: 0 : DaysToDate( nDate1, nDay1, nMonth1, nYear1 );
353 [ # # ]: 0 : DaysToDate( nDate2, nDay2, nMonth2, nYear2 );
354 : :
355 : : sal_uInt16 nYears;
356 : :
357 : : sal_Int32 nDayDiff, nDaysInYear;
358 : :
359 [ # # # # : 0 : switch( nMode )
# ]
360 : : {
361 : : case 0: // 0=USA (NASD) 30/360
362 : : case 4: // 4=Europe 30/360
363 : 0 : nDaysInYear = 360;
364 : 0 : nYears = nYear2 - nYear1;
365 : 0 : nDayDiff = GetDiffDate360( nDay1, nMonth1, nYear1, IsLeapYear( nYear1 ),
366 : 0 : nDay2, nMonth2, nYear2, nMode == 0 ) - nYears * nDaysInYear;
367 : 0 : break;
368 : : case 1: // 1=exact/exact
369 : 0 : nYears = nYear2 - nYear1;
370 : :
371 [ # # ]: 0 : nDaysInYear = IsLeapYear( nYear1 )? 366 : 365;
372 : :
373 [ # # ][ # # ]: 0 : if( nYears && ( nMonth1 > nMonth2 || ( nMonth1 == nMonth2 && nDay1 > nDay2 ) ) )
[ # # ][ # # ]
374 : 0 : nYears--;
375 : :
376 [ # # ]: 0 : if( nYears )
377 : 0 : nDayDiff = nDate2 - DateToDays( nDay1, nMonth1, nYear2 );
378 : : else
379 : 0 : nDayDiff = nDate2 - nDate1;
380 : :
381 [ # # ]: 0 : if( nDayDiff < 0 )
382 : 0 : nDayDiff += nDaysInYear;
383 : :
384 : 0 : break;
385 : : case 2: // 2=exact/360
386 : 0 : nDaysInYear = 360;
387 : 0 : nYears = sal_uInt16( ( nDate2 - nDate1 ) / nDaysInYear );
388 : 0 : nDayDiff = nDate2 - nDate1;
389 : 0 : nDayDiff %= nDaysInYear;
390 : 0 : break;
391 : : case 3: //3=exact/365
392 : 0 : nDaysInYear = 365;
393 : 0 : nYears = sal_uInt16( ( nDate2 - nDate1 ) / nDaysInYear );
394 : 0 : nDayDiff = nDate2 - nDate1;
395 : 0 : nDayDiff %= nDaysInYear;
396 : 0 : break;
397 : : default:
398 [ # # ]: 0 : THROW_IAE;
399 : : }
400 : :
401 : 0 : rYears = nYears;
402 : 0 : rDayDiffPart = nDayDiff;
403 : 0 : rDaysInYear = nDaysInYear;
404 : 0 : }
405 : :
406 : :
407 : 0 : sal_Int32 GetDiffDate( sal_Int32 nNullDate, sal_Int32 nStartDate, sal_Int32 nEndDate, sal_Int32 nMode,
408 : : sal_Int32* pOptDaysIn1stYear ) THROWDEF_RTE_IAE
409 : : {
410 : 0 : sal_Bool bNeg = nStartDate > nEndDate;
411 : :
412 [ # # ]: 0 : if( bNeg )
413 : : {
414 : 0 : sal_Int32 n = nEndDate;
415 : 0 : nEndDate = nStartDate;
416 : 0 : nStartDate = n;
417 : : }
418 : :
419 : : sal_Int32 nRet;
420 : :
421 [ # # # # : 0 : switch( nMode )
# ]
422 : : {
423 : : case 0: // 0=USA (NASD) 30/360
424 : : case 4: // 4=Europe 30/360
425 : : {
426 : : sal_uInt16 nD1, nM1, nY1, nD2, nM2, nY2;
427 : :
428 : 0 : nStartDate += nNullDate;
429 : 0 : nEndDate += nNullDate;
430 : :
431 [ # # ]: 0 : DaysToDate( nStartDate, nD1, nM1, nY1 );
432 [ # # ]: 0 : DaysToDate( nEndDate, nD2, nM2, nY2 );
433 : :
434 : 0 : sal_Bool bLeap = IsLeapYear( nY1 );
435 : : sal_Int32 nDays, nMonths;
436 : :
437 : 0 : nMonths = nM2 - nM1;
438 : 0 : nDays = nD2 - nD1;
439 : :
440 : 0 : nMonths += ( nY2 - nY1 ) * 12;
441 : :
442 : 0 : nRet = nMonths * 30 + nDays;
443 [ # # ][ # # ]: 0 : if( nMode == 0 && nM1 == 2 && nM2 != 2 && nY1 == nY2 )
[ # # ][ # # ]
444 [ # # ]: 0 : nRet -= bLeap? 1 : 2;
445 : :
446 [ # # ]: 0 : if( pOptDaysIn1stYear )
447 : 0 : *pOptDaysIn1stYear = 360;
448 : : }
449 : 0 : break;
450 : : case 1: // 1=exact/exact
451 [ # # ]: 0 : if( pOptDaysIn1stYear )
452 : : {
453 : : sal_uInt16 nD, nM, nY;
454 : :
455 [ # # ]: 0 : DaysToDate( nStartDate + nNullDate, nD, nM, nY );
456 : :
457 [ # # ]: 0 : *pOptDaysIn1stYear = IsLeapYear( nY )? 366 : 365;
458 : : }
459 : 0 : nRet = nEndDate - nStartDate;
460 : 0 : break;
461 : : case 2: // 2=exact/360
462 : 0 : nRet = nEndDate - nStartDate;
463 [ # # ]: 0 : if( pOptDaysIn1stYear )
464 : 0 : *pOptDaysIn1stYear = 360;
465 : 0 : break;
466 : : case 3: //3=exact/365
467 : 0 : nRet = nEndDate - nStartDate;
468 [ # # ]: 0 : if( pOptDaysIn1stYear )
469 : 0 : *pOptDaysIn1stYear = 365;
470 : 0 : break;
471 : : default:
472 [ # # ]: 0 : THROW_IAE;
473 : : }
474 : :
475 [ # # ]: 0 : return bNeg? -nRet : nRet;
476 : : }
477 : :
478 : :
479 : 0 : double GetYearDiff( sal_Int32 nNullDate, sal_Int32 nStartDate, sal_Int32 nEndDate, sal_Int32 nMode ) THROWDEF_RTE_IAE
480 : : {
481 : : sal_Int32 nDays1stYear;
482 [ # # ]: 0 : sal_Int32 nTotalDays = GetDiffDate( nNullDate, nStartDate, nEndDate, nMode, &nDays1stYear );
483 : :
484 : 0 : return double( nTotalDays ) / double( nDays1stYear );
485 : : }
486 : :
487 : :
488 : 0 : sal_Int32 GetDaysInYear( sal_Int32 nNullDate, sal_Int32 nDate, sal_Int32 nMode ) THROWDEF_RTE_IAE
489 : : {
490 [ # # # # ]: 0 : switch( nMode )
491 : : {
492 : : case 0: // 0=USA (NASD) 30/360
493 : : case 2: // 2=exact/360
494 : : case 4: // 4=Europe 30/360
495 : 0 : return 360;
496 : : case 1: // 1=exact/exact
497 : : {
498 : : sal_uInt16 nD, nM, nY;
499 : 0 : nDate += nNullDate;
500 [ # # ]: 0 : DaysToDate( nDate, nD, nM, nY );
501 [ # # ]: 0 : return IsLeapYear( nY )? 366 : 365;
502 : : }
503 : : case 3: //3=exact/365
504 : 0 : return 365;
505 : : default:
506 [ # # ]: 0 : THROW_IAE;
507 : : }
508 : : }
509 : :
510 : :
511 : 0 : double GetYearFrac( sal_Int32 nNullDate, sal_Int32 nStartDate, sal_Int32 nEndDate, sal_Int32 nMode ) THROWDEF_RTE_IAE
512 : : {
513 [ # # ]: 0 : if( nStartDate == nEndDate )
514 : 0 : return 0.0; // nothing to do...
515 : :
516 : : sal_uInt16 nYears;
517 : : sal_Int32 nDayDiff, nDaysInYear;
518 : :
519 [ # # ]: 0 : GetDiffParam( nNullDate, nStartDate, nEndDate, nMode, nYears, nDayDiff, nDaysInYear );
520 : :
521 : 0 : return double( nYears ) + double( nDayDiff ) / double( nDaysInYear );
522 : : }
523 : :
524 : 0 : double BinomialCoefficient( double n, double k )
525 : : {
526 : : // This method is a copy of BinomKoeff()
527 : : // found in sc/source/core/tool/interpr3.cxx
528 : :
529 : 0 : double nVal = 0.0;
530 : 0 : k = ::rtl::math::approxFloor(k);
531 [ # # ]: 0 : if (n < k)
532 : 0 : nVal = 0.0;
533 [ # # ]: 0 : else if (k == 0.0)
534 : 0 : nVal = 1.0;
535 : : else
536 : : {
537 : 0 : nVal = n/k;
538 : 0 : n--;
539 : 0 : k--;
540 [ # # ]: 0 : while (k > 0.0)
541 : : {
542 : 0 : nVal *= n/k;
543 : 0 : k--;
544 : 0 : n--;
545 : : }
546 : : }
547 : 0 : return nVal;
548 : : }
549 : :
550 : 0 : double GetGcd( double f1, double f2 )
551 : : {
552 : 0 : double f = fmod( f1, f2 );
553 [ # # ]: 0 : while( f > 0.0 )
554 : : {
555 : 0 : f1 = f2;
556 : 0 : f2 = f;
557 : 0 : f = fmod( f1, f2 );
558 : : }
559 : :
560 : 0 : return f2;
561 : : }
562 : :
563 : :
564 : 0 : double ConvertToDec( const STRING& aStr, sal_uInt16 nBase, sal_uInt16 nCharLim ) THROWDEF_RTE_IAE
565 : : {
566 [ # # ][ # # ]: 0 : if ( nBase < 2 || nBase > 36 )
567 [ # # ]: 0 : THROW_IAE;
568 : :
569 : 0 : sal_uInt32 nStrLen = aStr.getLength();
570 [ # # ]: 0 : if( nStrLen > nCharLim )
571 [ # # ]: 0 : THROW_IAE;
572 [ # # ]: 0 : else if( !nStrLen )
573 : 0 : return 0.0;
574 : :
575 : 0 : double fVal = 0.0;
576 : :
577 : 0 : register const sal_Unicode* p = aStr.getStr();
578 : :
579 : 0 : sal_uInt16 nFirstDig = 0;
580 : 0 : sal_Bool bFirstDig = sal_True;
581 : 0 : double fBase = nBase;
582 : :
583 [ # # ]: 0 : while ( *p )
584 : : {
585 : : sal_uInt16 n;
586 : :
587 [ # # ][ # # ]: 0 : if( '0' <= *p && *p <= '9' )
588 : 0 : n = *p - '0';
589 [ # # ][ # # ]: 0 : else if( 'A' <= *p && *p <= 'Z' )
590 : 0 : n = 10 + ( *p - 'A' );
591 [ # # ][ # # ]: 0 : else if ( 'a' <= *p && *p <= 'z' )
592 : 0 : n = 10 + ( *p - 'a' );
593 : : else
594 : 0 : n = nBase;
595 : :
596 [ # # ]: 0 : if( n < nBase )
597 : : {
598 [ # # ]: 0 : if( bFirstDig )
599 : : {
600 : 0 : bFirstDig = sal_False;
601 : 0 : nFirstDig = n;
602 : : }
603 : 0 : fVal = fVal * fBase + double( n );
604 : : }
605 : : else
606 : : // illegal char!
607 [ # # ]: 0 : THROW_IAE;
608 : :
609 : 0 : p++;
610 : :
611 : : }
612 : :
613 [ # # ][ # # ]: 0 : if( nStrLen == nCharLim && !bFirstDig && (nFirstDig >= nBase / 2) )
[ # # ]
614 : : { // handling negativ values
615 : 0 : fVal = ( pow( double( nBase ), double( nCharLim ) ) - fVal ); // complement
616 : 0 : fVal *= -1.0;
617 : : }
618 : :
619 : 0 : return fVal;
620 : : }
621 : :
622 : :
623 : 0 : static inline sal_Char GetMaxChar( sal_uInt16 nBase )
624 : : {
625 : 0 : const sal_Char* c = "--123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
626 : 0 : return c[ nBase ];
627 : : }
628 : :
629 : :
630 : 0 : STRING ConvertFromDec( double fNum, double fMin, double fMax, sal_uInt16 nBase,
631 : : sal_Int32 nPlaces, sal_Int32 nMaxPlaces, sal_Bool bUsePlaces ) THROWDEF_RTE_IAE
632 : : {
633 : 0 : fNum = ::rtl::math::approxFloor( fNum );
634 : 0 : fMin = ::rtl::math::approxFloor( fMin );
635 : 0 : fMax = ::rtl::math::approxFloor( fMax );
636 : :
637 [ # # ][ # # ]: 0 : if( fNum < fMin || fNum > fMax || ( bUsePlaces && ( nPlaces <= 0 || nPlaces > nMaxPlaces ) ) )
[ # # ][ # # ]
[ # # ]
638 [ # # ]: 0 : THROW_IAE;
639 : :
640 : 0 : sal_Int64 nNum = static_cast< sal_Int64 >( fNum );
641 : 0 : sal_Bool bNeg = nNum < 0;
642 [ # # ]: 0 : if( bNeg )
643 : 0 : nNum = sal_Int64( pow( double( nBase ), double( nMaxPlaces ) ) ) + nNum;
644 : :
645 : 0 : STRING aRet( STRING::valueOf( nNum, nBase ).toAsciiUpperCase() );
646 : :
647 : :
648 [ # # ]: 0 : if( bUsePlaces )
649 : : {
650 : 0 : sal_Int32 nLen = aRet.getLength();
651 [ # # ][ # # ]: 0 : if( !bNeg && nLen > nPlaces )
652 : : {
653 [ # # ]: 0 : THROW_IAE;
654 : : }
655 [ # # ][ # # ]: 0 : else if( ( bNeg && nLen < nMaxPlaces ) || ( !bNeg && nLen < nPlaces ) )
[ # # ][ # # ]
656 : : {
657 : 0 : sal_Int32 nLeft = nPlaces - nLen;
658 [ # # ]: 0 : sal_Char* p = new sal_Char[ nLeft + 1 ];
659 [ # # ]: 0 : memset( p, bNeg? GetMaxChar( nBase ) : '0', nLeft );
660 : 0 : p[ nLeft ] = 0x00;
661 [ # # ]: 0 : STRING aTmp( p, nLeft, RTL_TEXTENCODING_MS_1252 );
662 : 0 : aTmp += aRet;
663 : 0 : aRet = aTmp;
664 : :
665 [ # # ]: 0 : delete[] p;
666 : : }
667 : : }
668 : :
669 : 0 : return aRet;
670 : : }
671 : :
672 : : // implementation moved to module sal, see #i97091#
673 : 0 : double Erf( double x )
674 : : {
675 : 0 : return ::rtl::math::erf(x);
676 : : }
677 : :
678 : : // implementation moved to module sal, see #i97091#
679 : 0 : double Erfc( double x )
680 : : {
681 : 0 : return ::rtl::math::erfc(x);
682 : : }
683 : :
684 : 0 : inline sal_Bool IsNum( sal_Unicode c )
685 : : {
686 [ # # ][ # # ]: 0 : return c >= '0' && c <= '9';
687 : : }
688 : :
689 : :
690 : 0 : inline sal_Bool IsComma( sal_Unicode c )
691 : : {
692 [ # # ][ # # ]: 0 : return c == '.' || c == ',';
693 : : }
694 : :
695 : :
696 : 0 : inline sal_Bool IsExpStart( sal_Unicode c )
697 : : {
698 [ # # ][ # # ]: 0 : return c == 'e' || c == 'E';
699 : : }
700 : :
701 : :
702 : 0 : inline sal_Bool IsImagUnit( sal_Unicode c )
703 : : {
704 [ # # ][ # # ]: 0 : return c == 'i' || c == 'j';
705 : : }
706 : :
707 : :
708 : 0 : inline sal_uInt16 GetVal( sal_Unicode c )
709 : : {
710 : 0 : return sal_uInt16( c - '0' );
711 : : }
712 : :
713 : :
714 : 0 : sal_Bool ParseDouble( const sal_Unicode*& rp, double& rRet )
715 : : {
716 : 0 : double fInt = 0.0;
717 : 0 : double fFrac = 0.0;
718 : 0 : double fMult = 0.1; // multiplier to multiply digits with, when adding fractional ones
719 : 0 : sal_Int32 nExp = 0;
720 : 0 : sal_Int32 nMaxExp = 307;
721 : 0 : sal_uInt16 nDigCnt = 18; // max. number of digits to read in, rest doesn't matter
722 : :
723 : : enum State { S_End = 0, S_Sign, S_IntStart, S_Int, S_IgnoreIntDigs, S_Frac, S_IgnoreFracDigs, S_ExpSign, S_Exp };
724 : :
725 : 0 : State eS = S_Sign;
726 : :
727 : 0 : sal_Bool bNegNum = sal_False;
728 : 0 : sal_Bool bNegExp = sal_False;
729 : :
730 : 0 : const sal_Unicode* p = rp;
731 : : sal_Unicode c;
732 : :
733 [ # # ]: 0 : while( eS )
734 : : {
735 : 0 : c = *p;
736 [ # # # # : 0 : switch( eS )
# # # # #
# ]
737 : : {
738 : : case S_Sign:
739 [ # # ]: 0 : if( IsNum( c ) )
740 : : {
741 : 0 : fInt = GetVal( c );
742 : 0 : nDigCnt--;
743 : 0 : eS = S_Int;
744 : : }
745 [ # # ]: 0 : else if( c == '-' )
746 : : {
747 : 0 : bNegNum = sal_True;
748 : 0 : eS = S_IntStart;
749 : : }
750 [ # # ]: 0 : else if( c == '+' )
751 : 0 : eS = S_IntStart;
752 [ # # ]: 0 : else if( IsComma( c ) )
753 : 0 : eS = S_Frac;
754 : : else
755 : 0 : return sal_False;
756 : 0 : break;
757 : : case S_IntStart:
758 [ # # ]: 0 : if( IsNum( c ) )
759 : : {
760 : 0 : fInt = GetVal( c );
761 : 0 : nDigCnt--;
762 : 0 : eS = S_Int;
763 : : }
764 [ # # ]: 0 : else if( IsComma( c ) )
765 : 0 : eS = S_Frac;
766 [ # # ]: 0 : else if( IsImagUnit( c ) )
767 : : {
768 : 0 : rRet = 0.0;
769 : 0 : return sal_True;
770 : : }
771 : : else
772 : 0 : return sal_False;
773 : 0 : break;
774 : : case S_Int:
775 [ # # ]: 0 : if( IsNum( c ) )
776 : : {
777 : 0 : fInt *= 10.0;
778 : 0 : fInt += double( GetVal( c ) );
779 : 0 : nDigCnt--;
780 [ # # ]: 0 : if( !nDigCnt )
781 : 0 : eS = S_IgnoreIntDigs;
782 : : }
783 [ # # ]: 0 : else if( IsComma( c ) )
784 : 0 : eS = S_Frac;
785 [ # # ]: 0 : else if( IsExpStart( c ) )
786 : 0 : eS = S_ExpSign;
787 : : else
788 : 0 : eS = S_End;
789 : 0 : break;
790 : : case S_IgnoreIntDigs:
791 [ # # ]: 0 : if( IsNum( c ) )
792 : 0 : nExp++; // just multiply num with 10... ;-)
793 [ # # ]: 0 : else if( IsComma( c ) )
794 : 0 : eS = S_Frac;
795 [ # # ]: 0 : else if( IsExpStart( c ) )
796 : 0 : eS = S_ExpSign;
797 : : else
798 : 0 : eS = S_End;
799 : 0 : break;
800 : : case S_Frac:
801 [ # # ]: 0 : if( IsNum( c ) )
802 : : {
803 : 0 : fFrac += double( GetVal( c ) ) * fMult;
804 : 0 : nDigCnt--;
805 [ # # ]: 0 : if( nDigCnt )
806 : 0 : fMult *= 0.1;
807 : : else
808 : 0 : eS = S_IgnoreFracDigs;
809 : : }
810 [ # # ]: 0 : else if( IsExpStart( c ) )
811 : 0 : eS = S_ExpSign;
812 : : else
813 : 0 : eS = S_End;
814 : 0 : break;
815 : : case S_IgnoreFracDigs:
816 [ # # ]: 0 : if( IsExpStart( c ) )
817 : 0 : eS = S_ExpSign;
818 [ # # ]: 0 : else if( !IsNum( c ) )
819 : 0 : eS = S_End;
820 : 0 : break;
821 : : case S_ExpSign:
822 [ # # ]: 0 : if( IsNum( c ) )
823 : : {
824 : 0 : nExp = GetVal( c );
825 : 0 : eS = S_Exp;
826 : : }
827 [ # # ]: 0 : else if( c == '-' )
828 : : {
829 : 0 : bNegExp = sal_True;
830 : 0 : eS = S_Exp;
831 : : }
832 [ # # ]: 0 : else if( c != '+' )
833 : 0 : eS = S_End;
834 : 0 : break;
835 : : case S_Exp:
836 [ # # ]: 0 : if( IsNum( c ) )
837 : : {
838 : 0 : nExp *= 10;
839 : 0 : nExp += GetVal( c );
840 [ # # ]: 0 : if( nExp > nMaxExp )
841 : 0 : return sal_False;
842 : : }
843 : : else
844 : 0 : eS = S_End;
845 : 0 : break;
846 : : case S_End: // to avoid compiler warning
847 : 0 : break; // loop exits anyway
848 : : }
849 : :
850 : 0 : p++;
851 : : }
852 : :
853 : 0 : p--; // set pointer back to last
854 : 0 : rp = p;
855 : :
856 : 0 : fInt += fFrac;
857 : 0 : sal_Int32 nLog10 = sal_Int32( log10( fInt ) );
858 : :
859 [ # # ]: 0 : if( bNegExp )
860 : 0 : nExp = -nExp;
861 : :
862 [ # # ]: 0 : if( nLog10 + nExp > nMaxExp )
863 : 0 : return sal_False;
864 : :
865 : 0 : fInt = ::rtl::math::pow10Exp( fInt, nExp );
866 : :
867 [ # # ]: 0 : if( bNegNum )
868 : 0 : fInt = -fInt;
869 : :
870 : 0 : rRet = fInt;
871 : :
872 : 0 : return sal_True;
873 : : }
874 : :
875 : :
876 : 0 : STRING GetString( double f, sal_Bool bLeadingSign, sal_uInt16 nMaxDig )
877 : : {
878 : 0 : const int nBuff = 256;
879 : : sal_Char aBuff[ nBuff + 1 ];
880 [ # # ]: 0 : const char* pFormStr = bLeadingSign? "%+.*g" : "%.*g";
881 : 0 : int nLen = snprintf( aBuff, nBuff, pFormStr, int( nMaxDig ), f );
882 : : // you never know which underlying implementation you get ...
883 : 0 : aBuff[nBuff] = 0;
884 [ # # ][ # # ]: 0 : if ( nLen < 0 || nLen > nBuff )
885 : 0 : nLen = strlen( aBuff );
886 : :
887 [ # # ]: 0 : STRING aRet( aBuff, nLen, RTL_TEXTENCODING_MS_1252 );
888 : :
889 : 0 : return aRet;
890 : : }
891 : :
892 : :
893 : 0 : double GetAmordegrc( sal_Int32 nNullDate, double fCost, sal_Int32 nDate, sal_Int32 nFirstPer,
894 : : double fRestVal, double fPer, double fRate, sal_Int32 nBase ) THROWDEF_RTE_IAE
895 : : {
896 [ # # ]: 0 : if( nBase == 2 )
897 [ # # ]: 0 : THROW_IAE;
898 : :
899 : 0 : sal_uInt32 nPer = sal_uInt32( fPer );
900 : 0 : double fUsePer = 1.0 / fRate;
901 : : double fAmorCoeff;
902 : :
903 [ # # ]: 0 : if( fUsePer < 3.0 )
904 : 0 : fAmorCoeff = 1.0;
905 [ # # ]: 0 : else if( fUsePer < 5.0 )
906 : 0 : fAmorCoeff = 1.5;
907 [ # # ]: 0 : else if( fUsePer <= 6.0 )
908 : 0 : fAmorCoeff = 2.0;
909 : : else
910 : 0 : fAmorCoeff = 2.5;
911 : :
912 : 0 : fRate *= fAmorCoeff;
913 : 0 : double fNRate = ::rtl::math::round( GetYearFrac( nNullDate, nDate, nFirstPer, nBase ) * fRate * fCost, 0 );
914 : 0 : fCost -= fNRate;
915 : 0 : double fRest = fCost - fRestVal; // Anschaffungskosten - Restwert - Summe aller Abschreibungen
916 : :
917 [ # # ]: 0 : for( sal_uInt32 n = 0 ; n < nPer ; n++ )
918 : : {
919 : 0 : fNRate = ::rtl::math::round( fRate * fCost, 0 );
920 : 0 : fRest -= fNRate;
921 : :
922 [ # # ]: 0 : if( fRest < 0.0 )
923 : : {
924 [ # # ]: 0 : switch( nPer - n )
925 : : {
926 : : case 0:
927 : : case 1:
928 : 0 : return ::rtl::math::round( fCost * 0.5, 0 );
929 : : default:
930 : 0 : return 0.0;
931 : : }
932 : : }
933 : :
934 : 0 : fCost -= fNRate;
935 : : }
936 : :
937 : 0 : return fNRate;
938 : : }
939 : :
940 : :
941 : 0 : double GetAmorlinc( sal_Int32 nNullDate, double fCost, sal_Int32 nDate, sal_Int32 nFirstPer,
942 : : double fRestVal, double fPer, double fRate, sal_Int32 nBase ) THROWDEF_RTE_IAE
943 : : {
944 [ # # ]: 0 : if( nBase == 2 )
945 [ # # ]: 0 : THROW_IAE;
946 : :
947 : 0 : sal_uInt32 nPer = sal_uInt32( fPer );
948 : 0 : double fOneRate = fCost * fRate;
949 : 0 : double fCostDelta = fCost - fRestVal;
950 : 0 : double f0Rate = GetYearFrac( nNullDate, nDate, nFirstPer, nBase ) * fRate * fCost;
951 : 0 : sal_uInt32 nNumOfFullPeriods = sal_uInt32( ( fCost - fRestVal - f0Rate) / fOneRate );
952 : :
953 [ # # ]: 0 : if( nPer == 0 )
954 : 0 : return f0Rate;
955 [ # # ]: 0 : else if( nPer <= nNumOfFullPeriods )
956 : 0 : return fOneRate;
957 [ # # ]: 0 : else if( nPer == nNumOfFullPeriods + 1 )
958 : 0 : return fCostDelta - fOneRate * nNumOfFullPeriods - f0Rate;
959 : : else
960 : 0 : return 0.0;
961 : : }
962 : :
963 : :
964 : 0 : double GetDuration( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, double fCoup,
965 : : double fYield, sal_Int32 nFreq, sal_Int32 nBase ) THROWDEF_RTE_IAE
966 : : {
967 : 0 : double fYearfrac = GetYearFrac( nNullDate, nSettle, nMat, nBase );
968 : 0 : double fNumOfCoups = GetCoupnum( nNullDate, nSettle, nMat, nFreq, nBase );
969 : 0 : double fDur = 0.0;
970 : 0 : const double f100 = 100.0;
971 : 0 : fCoup *= f100 / double( nFreq ); // fCoup is used as cash flow
972 : 0 : fYield /= nFreq;
973 : 0 : fYield += 1.0;
974 : :
975 : 0 : double nDiff = fYearfrac * nFreq - fNumOfCoups;
976 : :
977 : : double t;
978 : :
979 [ # # ]: 0 : for( t = 1.0 ; t < fNumOfCoups ; t++ )
980 : 0 : fDur += ( t + nDiff ) * ( fCoup ) / pow( fYield, t + nDiff );
981 : :
982 : 0 : fDur += ( fNumOfCoups + nDiff ) * ( fCoup + f100 ) / pow( fYield, fNumOfCoups + nDiff );
983 : :
984 : 0 : double p = 0.0;
985 [ # # ]: 0 : for( t = 1.0 ; t < fNumOfCoups ; t++ )
986 : 0 : p += fCoup / pow( fYield, t + nDiff );
987 : :
988 : 0 : p += ( fCoup + f100 ) / pow( fYield, fNumOfCoups + nDiff );
989 : :
990 : 0 : fDur /= p;
991 : 0 : fDur /= double( nFreq );
992 : :
993 : 0 : return fDur;
994 : : }
995 : :
996 : :
997 : 0 : double GetYieldmat( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nIssue,
998 : : double fRate, double fPrice, sal_Int32 nBase ) THROWDEF_RTE_IAE
999 : : {
1000 : 0 : double fIssMat = GetYearFrac( nNullDate, nIssue, nMat, nBase );
1001 : 0 : double fIssSet = GetYearFrac( nNullDate, nIssue, nSettle, nBase );
1002 : 0 : double fSetMat = GetYearFrac( nNullDate, nSettle, nMat, nBase );
1003 : :
1004 : 0 : double y = 1.0 + fIssMat * fRate;
1005 : 0 : y /= fPrice / 100.0 + fIssSet * fRate;
1006 : 0 : y--;
1007 : 0 : y /= fSetMat;
1008 : :
1009 : 0 : return y;
1010 : : }
1011 : :
1012 : :
1013 : 0 : double GetOddfprice( sal_Int32 /*nNullDate*/, sal_Int32 /*nSettle*/, sal_Int32 /*nMat*/, sal_Int32 /*nIssue*/,
1014 : : sal_Int32 /*nFirstCoup*/, double /*fRate*/, double /*fYield*/, double /*fRedemp*/, sal_Int32 /*nFreq*/,
1015 : : sal_Int32 /*nBase*/ ) THROWDEF_RTE_IAE
1016 : : {
1017 [ # # ]: 0 : THROW_RTE; // #87380#
1018 : : }
1019 : :
1020 : :
1021 : 0 : double getYield_( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, double fCoup, double fPrice,
1022 : : double fRedemp, sal_Int32 nFreq, sal_Int32 nBase ) THROWDEF_RTE_IAE
1023 : : {
1024 : 0 : double fRate = fCoup;
1025 : 0 : double fPriceN = 0.0;
1026 : 0 : double fYield1 = 0.0;
1027 : 0 : double fYield2 = 1.0;
1028 : 0 : double fPrice1 = getPrice_( nNullDate, nSettle, nMat, fRate, fYield1, fRedemp, nFreq, nBase );
1029 : 0 : double fPrice2 = getPrice_( nNullDate, nSettle, nMat, fRate, fYield2, fRedemp, nFreq, nBase );
1030 : 0 : double fYieldN = ( fYield2 - fYield1 ) * 0.5;
1031 : :
1032 [ # # ][ # # ]: 0 : for( sal_uInt32 nIter = 0 ; nIter < 100 && fPriceN != fPrice ; nIter++ )
[ # # ]
1033 : : {
1034 : 0 : fPriceN = getPrice_( nNullDate, nSettle, nMat, fRate, fYieldN, fRedemp, nFreq, nBase );
1035 : :
1036 [ # # ]: 0 : if( fPrice == fPrice1 )
1037 : 0 : return fYield1;
1038 [ # # ]: 0 : else if( fPrice == fPrice2 )
1039 : 0 : return fYield2;
1040 [ # # ]: 0 : else if( fPrice == fPriceN )
1041 : 0 : return fYieldN;
1042 [ # # ]: 0 : else if( fPrice < fPrice2 )
1043 : : {
1044 : 0 : fYield2 *= 2.0;
1045 : 0 : fPrice2 = getPrice_( nNullDate, nSettle, nMat, fRate, fYield2, fRedemp, nFreq, nBase );
1046 : :
1047 : 0 : fYieldN = ( fYield2 - fYield1 ) * 0.5;
1048 : : }
1049 : : else
1050 : : {
1051 [ # # ]: 0 : if( fPrice < fPriceN )
1052 : : {
1053 : 0 : fYield1 = fYieldN;
1054 : 0 : fPrice1 = fPriceN;
1055 : : }
1056 : : else
1057 : : {
1058 : 0 : fYield2 = fYieldN;
1059 : 0 : fPrice2 = fPriceN;
1060 : : }
1061 : :
1062 : 0 : fYieldN = fYield2 - ( fYield2 - fYield1 ) * ( ( fPrice - fPrice2 ) / ( fPrice1 - fPrice2 ) );
1063 : : }
1064 : : }
1065 : :
1066 [ # # ]: 0 : if( fabs( fPrice - fPriceN ) > fPrice / 100.0 )
1067 [ # # ]: 0 : THROW_IAE; // result not precise enough
1068 : :
1069 : 0 : return fYieldN;
1070 : : }
1071 : :
1072 : :
1073 : 0 : double getPrice_( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, double fRate, double fYield,
1074 : : double fRedemp, sal_Int32 nFreq, sal_Int32 nBase ) THROWDEF_RTE_IAE
1075 : : {
1076 : 0 : double fFreq = nFreq;
1077 : :
1078 : 0 : double fE = GetCoupdays( nNullDate, nSettle, nMat, nFreq, nBase );
1079 : 0 : double fDSC_E = GetCoupdaysnc( nNullDate, nSettle, nMat, nFreq, nBase ) / fE;
1080 : 0 : double fN = GetCoupnum( nNullDate, nSettle, nMat, nFreq, nBase );
1081 : 0 : double fA = GetCoupdaybs( nNullDate, nSettle, nMat, nFreq, nBase );
1082 : :
1083 : 0 : double fRet = fRedemp / ( pow( 1.0 + fYield / fFreq, fN - 1.0 + fDSC_E ) );
1084 : 0 : fRet -= 100.0 * fRate / fFreq * fA / fE;
1085 : :
1086 : 0 : double fT1 = 100.0 * fRate / fFreq;
1087 : 0 : double fT2 = 1.0 + fYield / fFreq;
1088 : :
1089 [ # # ]: 0 : for( double fK = 0.0 ; fK < fN ; fK++ )
1090 : 0 : fRet += fT1 / pow( fT2, fK + fDSC_E );
1091 : :
1092 : 0 : return fRet;
1093 : : }
1094 : :
1095 : :
1096 : 0 : double GetOddfyield( sal_Int32 /*nNullDate*/, sal_Int32 /*nSettle*/, sal_Int32 /*nMat*/, sal_Int32 /*nIssue*/,
1097 : : sal_Int32 /*nFirstCoup*/, double /*fRate*/, double /*fPrice*/, double /*fRedemp*/, sal_Int32 /*nFreq*/,
1098 : : sal_Int32 /*nBase*/ ) THROWDEF_RTE_IAE
1099 : : {
1100 [ # # ]: 0 : THROW_RTE; // #87380#
1101 : : }
1102 : :
1103 : :
1104 : 0 : double GetOddlprice( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nLastCoup,
1105 : : double fRate, double fYield, double fRedemp, sal_Int32 nFreq, sal_Int32 nBase ) THROWDEF_RTE_IAE
1106 : : {
1107 : 0 : double fFreq = double( nFreq );
1108 : 0 : double fDCi = GetYearFrac( nNullDate, nLastCoup, nMat, nBase ) * fFreq;
1109 : 0 : double fDSCi = GetYearFrac( nNullDate, nSettle, nMat, nBase ) * fFreq;
1110 : 0 : double fAi = GetYearFrac( nNullDate, nLastCoup, nSettle, nBase ) * fFreq;
1111 : :
1112 : 0 : double p = fRedemp + fDCi * 100.0 * fRate / fFreq;
1113 : 0 : p /= fDSCi * fYield / fFreq + 1.0;
1114 : 0 : p -= fAi * 100.0 * fRate / fFreq;
1115 : :
1116 : 0 : return p;
1117 : : }
1118 : :
1119 : :
1120 : 0 : double GetOddlyield( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nLastCoup,
1121 : : double fRate, double fPrice, double fRedemp, sal_Int32 nFreq, sal_Int32 nBase ) THROWDEF_RTE_IAE
1122 : : {
1123 : 0 : double fFreq = double( nFreq );
1124 : 0 : double fDCi = GetYearFrac( nNullDate, nLastCoup, nMat, nBase ) * fFreq;
1125 : 0 : double fDSCi = GetYearFrac( nNullDate, nSettle, nMat, nBase ) * fFreq;
1126 : 0 : double fAi = GetYearFrac( nNullDate, nLastCoup, nSettle, nBase ) * fFreq;
1127 : :
1128 : 0 : double y = fRedemp + fDCi * 100.0 * fRate / fFreq;
1129 : 0 : y /= fPrice + fAi * 100.0 * fRate / fFreq;
1130 : 0 : y--;
1131 : 0 : y *= fFreq / fDSCi;
1132 : :
1133 : 0 : return y;
1134 : : }
1135 : :
1136 : :
1137 : 0 : double GetRmz( double fZins, double fZzr, double fBw, double fZw, sal_Int32 nF )
1138 : : {
1139 : : double fRmz;
1140 [ # # ]: 0 : if( fZins == 0.0 )
1141 : 0 : fRmz = ( fBw + fZw ) / fZzr;
1142 : : else
1143 : : {
1144 : 0 : double fTerm = pow( 1.0 + fZins, fZzr );
1145 [ # # ]: 0 : if( nF > 0 )
1146 : 0 : fRmz = ( fZw * fZins / ( fTerm - 1.0 ) + fBw * fZins / ( 1.0 - 1.0 / fTerm ) ) / ( 1.0 + fZins );
1147 : : else
1148 : 0 : fRmz = fZw * fZins / ( fTerm - 1.0 ) + fBw * fZins / ( 1.0 - 1.0 / fTerm );
1149 : : }
1150 : :
1151 : 0 : return -fRmz;
1152 : : }
1153 : :
1154 : :
1155 : 0 : double GetZw( double fZins, double fZzr, double fRmz, double fBw, sal_Int32 nF )
1156 : : {
1157 : : double fZw;
1158 [ # # ]: 0 : if( fZins == 0.0 )
1159 : 0 : fZw = fBw + fRmz * fZzr;
1160 : : else
1161 : : {
1162 : 0 : double fTerm = pow( 1.0 + fZins, fZzr );
1163 [ # # ]: 0 : if( nF > 0 )
1164 : 0 : fZw = fBw * fTerm + fRmz * ( 1.0 + fZins ) * ( fTerm - 1.0 ) / fZins;
1165 : : else
1166 : 0 : fZw = fBw * fTerm + fRmz * ( fTerm - 1.0 ) / fZins;
1167 : : }
1168 : :
1169 : 0 : return -fZw;
1170 : : }
1171 : :
1172 : :
1173 : : //-----------------------------------------------------------------------------
1174 : : // financial functions COUP***
1175 : :
1176 : :
1177 : : //-------
1178 : : // COUPPCD: find last coupon date before settlement (can be equal to settlement)
1179 : 0 : void lcl_GetCouppcd( ScaDate& rDate, const ScaDate& rSettle, const ScaDate& rMat, sal_Int32 nFreq )
1180 : : throw( lang::IllegalArgumentException )
1181 : : {
1182 : 0 : rDate = rMat;
1183 : 0 : rDate.setYear( rSettle.getYear() );
1184 [ # # ]: 0 : if( rDate < rSettle )
1185 : 0 : rDate.addYears( 1 );
1186 [ # # ]: 0 : while( rDate > rSettle )
1187 : 0 : rDate.addMonths( -12 / nFreq );
1188 : 0 : }
1189 : :
1190 : 0 : double GetCouppcd( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq, sal_Int32 nBase )
1191 : : THROWDEF_RTE_IAE
1192 : : {
1193 [ # # ][ # # ]: 0 : if( nSettle >= nMat || CHK_Freq )
[ # # ][ # # ]
1194 [ # # ]: 0 : THROW_IAE;
1195 : :
1196 : 0 : ScaDate aDate;
1197 [ # # ][ # # ]: 0 : lcl_GetCouppcd( aDate, ScaDate( nNullDate, nSettle, nBase ), ScaDate( nNullDate, nMat, nBase ), nFreq );
[ # # ]
1198 [ # # ]: 0 : return aDate.getDate( nNullDate );
1199 : : }
1200 : :
1201 : :
1202 : : //-------
1203 : : // COUPNCD: find first coupon date after settlement (is never equal to settlement)
1204 : 0 : void lcl_GetCoupncd( ScaDate& rDate, const ScaDate& rSettle, const ScaDate& rMat, sal_Int32 nFreq )
1205 : : throw( lang::IllegalArgumentException )
1206 : : {
1207 : 0 : rDate = rMat;
1208 : 0 : rDate.setYear( rSettle.getYear() );
1209 [ # # ]: 0 : if( rDate > rSettle )
1210 : 0 : rDate.addYears( -1 );
1211 [ # # ]: 0 : while( rDate <= rSettle )
1212 : 0 : rDate.addMonths( 12 / nFreq );
1213 : 0 : }
1214 : :
1215 : 0 : double GetCoupncd( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq, sal_Int32 nBase )
1216 : : THROWDEF_RTE_IAE
1217 : : {
1218 [ # # ][ # # ]: 0 : if( nSettle >= nMat || CHK_Freq )
[ # # ][ # # ]
1219 [ # # ]: 0 : THROW_IAE;
1220 : :
1221 : 0 : ScaDate aDate;
1222 [ # # ][ # # ]: 0 : lcl_GetCoupncd( aDate, ScaDate( nNullDate, nSettle, nBase ), ScaDate( nNullDate, nMat, nBase ), nFreq );
[ # # ]
1223 [ # # ]: 0 : return aDate.getDate( nNullDate );
1224 : : }
1225 : :
1226 : :
1227 : : //-------
1228 : : // COUPDAYBS: get day count: coupon date before settlement <-> settlement
1229 : 0 : double GetCoupdaybs( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq, sal_Int32 nBase )
1230 : : THROWDEF_RTE_IAE
1231 : : {
1232 [ # # ][ # # ]: 0 : if( nSettle >= nMat || CHK_Freq )
[ # # ][ # # ]
1233 [ # # ]: 0 : THROW_IAE;
1234 : :
1235 [ # # ]: 0 : ScaDate aSettle( nNullDate, nSettle, nBase );
1236 : 0 : ScaDate aDate;
1237 [ # # ][ # # ]: 0 : lcl_GetCouppcd( aDate, aSettle, ScaDate( nNullDate, nMat, nBase ), nFreq );
1238 [ # # ]: 0 : return ScaDate::getDiff( aDate, aSettle );
1239 : : }
1240 : :
1241 : :
1242 : : //-------
1243 : : // COUPDAYSNC: get day count: settlement <-> coupon date after settlement
1244 : 0 : double GetCoupdaysnc( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq, sal_Int32 nBase )
1245 : : THROWDEF_RTE_IAE
1246 : : {
1247 [ # # ][ # # ]: 0 : if( nSettle >= nMat || CHK_Freq )
[ # # ][ # # ]
1248 [ # # ]: 0 : THROW_IAE;
1249 : :
1250 [ # # ][ # # ]: 0 : if( (nBase != 0) && (nBase != 4) )
1251 : : {
1252 [ # # ]: 0 : ScaDate aSettle( nNullDate, nSettle, nBase );
1253 : 0 : ScaDate aDate;
1254 [ # # ][ # # ]: 0 : lcl_GetCoupncd( aDate, aSettle, ScaDate( nNullDate, nMat, nBase ), nFreq );
1255 [ # # ]: 0 : return ScaDate::getDiff( aSettle, aDate );
1256 : : }
1257 : 0 : return GetCoupdays( nNullDate, nSettle, nMat, nFreq, nBase ) - GetCoupdaybs( nNullDate, nSettle, nMat, nFreq, nBase );
1258 : : }
1259 : :
1260 : :
1261 : : //-------
1262 : : // COUPDAYS: get day count: coupon date before settlement <-> coupon date after settlement
1263 : 0 : double GetCoupdays( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq, sal_Int32 nBase )
1264 : : THROWDEF_RTE_IAE
1265 : : {
1266 [ # # ][ # # ]: 0 : if( nSettle >= nMat || CHK_Freq )
[ # # ][ # # ]
1267 [ # # ]: 0 : THROW_IAE;
1268 : :
1269 [ # # ]: 0 : if( nBase == 1 )
1270 : : {
1271 : 0 : ScaDate aDate;
1272 [ # # ][ # # ]: 0 : lcl_GetCouppcd( aDate, ScaDate( nNullDate, nSettle, nBase ), ScaDate( nNullDate, nMat, nBase ), nFreq );
[ # # ]
1273 : 0 : ScaDate aNextDate( aDate );
1274 [ # # ]: 0 : aNextDate.addMonths( 12 / nFreq );
1275 [ # # ]: 0 : return ScaDate::getDiff( aDate, aNextDate );
1276 : : }
1277 : 0 : return static_cast< double >( GetDaysInYear( 0, 0, nBase ) ) / nFreq;
1278 : : }
1279 : :
1280 : :
1281 : : //-------
1282 : : // COUPNUM: get count of coupon dates
1283 : 0 : double GetCoupnum( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq, sal_Int32 nBase )
1284 : : THROWDEF_RTE_IAE
1285 : : {
1286 [ # # ][ # # ]: 0 : if( nSettle >= nMat || CHK_Freq )
[ # # ][ # # ]
1287 [ # # ]: 0 : THROW_IAE;
1288 : :
1289 [ # # ]: 0 : ScaDate aMat( nNullDate, nMat, nBase );
1290 : 0 : ScaDate aDate;
1291 [ # # ][ # # ]: 0 : lcl_GetCouppcd( aDate, ScaDate( nNullDate, nSettle, nBase ), aMat, nFreq );
1292 : 0 : sal_uInt16 nMonths = (aMat.getYear() - aDate.getYear()) * 12 + aMat.getMonth() - aDate.getMonth();
1293 : 0 : return static_cast< double >( nMonths * nFreq / 12 );
1294 : : }
1295 : :
1296 : :
1297 : :
1298 : :
1299 : :
1300 : :
1301 : :
1302 : : const sal_uInt32 MyList::nStartSize = 16;
1303 : : const sal_uInt32 MyList::nIncrSize = 16;
1304 : :
1305 : :
1306 : 102 : void MyList::_Grow( void )
1307 : : {
1308 : 102 : nSize += nIncrSize;
1309 : :
1310 : 102 : void** pNewData = new void*[ nSize ];
1311 : 102 : memcpy( pNewData, pData, nNew * sizeof( void* ) );
1312 : :
1313 [ + - ]: 102 : delete[] pData;
1314 : 102 : pData = pNewData;
1315 : 102 : }
1316 : :
1317 : :
1318 : 1734 : MyList::MyList( void )
1319 : : {
1320 : 1734 : nSize = nStartSize;
1321 : 1734 : pData = new void*[ nSize ];
1322 : 1734 : nNew = nAct = 0;
1323 : 1734 : }
1324 : :
1325 : :
1326 : 714 : MyList::~MyList()
1327 : : {
1328 [ + - ]: 714 : delete[] pData;
1329 [ - + ]: 714 : }
1330 : :
1331 : :
1332 : 0 : void MyList::Insert( void* p, sal_uInt32 n )
1333 : : {
1334 [ # # ]: 0 : if( n >= nNew )
1335 : 0 : Append( p );
1336 : : else
1337 : : {
1338 : 0 : Grow();
1339 : :
1340 : 0 : void** pIns = pData + n;
1341 : 0 : memmove( pIns + 1, pIns, ( nNew - n ) * sizeof( void* ) );
1342 : :
1343 : 0 : *pIns = p;
1344 : :
1345 : 0 : nNew++;
1346 : : }
1347 : 0 : }
1348 : :
1349 : :
1350 : :
1351 : :
1352 : 707 : StringList::~StringList()
1353 : : {
1354 [ + + ]: 2121 : for( STRING* p = ( STRING* ) First() ; p ; p = ( STRING* ) Next() )
1355 [ + - ]: 1414 : delete p;
1356 [ - + ]: 707 : }
1357 : :
1358 : :
1359 [ + - ]: 1717 : class AnalysisRscStrArrLoader : public Resource
1360 : : {
1361 : : private:
1362 : : ResStringArray aStrArray;
1363 : : public:
1364 : 1717 : AnalysisRscStrArrLoader( sal_uInt16 nRsc, sal_uInt16 nArrayId, ResMgr& rResMgr ) :
1365 : : Resource( AnalysisResId( nRsc, rResMgr ) ),
1366 [ + - ][ + - ]: 1717 : aStrArray( AnalysisResId( nArrayId, rResMgr ) )
1367 : : {
1368 [ + - ]: 1717 : FreeResource();
1369 : 1717 : }
1370 : :
1371 : 1717 : const ResStringArray& GetStringArray() const { return aStrArray; }
1372 : : };
1373 : :
1374 : :
1375 : :
1376 : :
1377 : 1717 : FuncData::FuncData( const FuncDataBase& r, ResMgr& rResMgr ) :
1378 : : aIntName( OUString::createFromAscii( r.pIntName ) ),
1379 : : nUINameID( r.nUINameID ),
1380 : : nDescrID( r.nDescrID ),
1381 : : bDouble( r.bDouble ),
1382 : : bWithOpt( r.bWithOpt ),
1383 : : nParam( r.nNumOfParams ),
1384 : : nCompID( r.nCompListID ),
1385 [ + - ]: 1717 : eCat( r.eCat )
1386 : : {
1387 [ + - ]: 1717 : AnalysisRscStrArrLoader aArrLoader( RID_ANALYSIS_DEFFUNCTION_NAMES, nCompID, rResMgr );
1388 : 1717 : const ResStringArray& rArr = aArrLoader.GetStringArray();
1389 : :
1390 : 1717 : sal_uInt16 nCount = sal::static_int_cast<sal_uInt16>( rArr.Count() );
1391 : : sal_uInt16 n;
1392 : :
1393 [ + + ]: 5151 : for( n = 0 ; n < nCount ; n++ )
1394 [ + - ][ + - ]: 5151 : aCompList.Append( rArr.GetString( n ) );
[ + - ]
1395 : 1717 : }
1396 : :
1397 : :
1398 : 707 : FuncData::~FuncData()
1399 : : {
1400 [ - + ]: 1414 : }
1401 : :
1402 : :
1403 : 9894 : sal_uInt16 FuncData::GetStrIndex( sal_uInt16 nParamNum ) const
1404 : : {
1405 [ + + ]: 9894 : if( !bWithOpt )
1406 : 2890 : nParamNum++;
1407 : :
1408 [ + + ]: 9894 : if( nParamNum > nParam )
1409 : 170 : return nParam * 2;
1410 : : else
1411 : 9894 : return nParamNum * 2;
1412 : : }
1413 : :
1414 : :
1415 : :
1416 : :
1417 : 17 : FuncDataList::FuncDataList( ResMgr& rResMgr )
1418 : : {
1419 [ + + ]: 1734 : for( sal_uInt16 n = 0 ; n < SAL_N_ELEMENTS(pFuncDatas) ; n++ )
1420 [ + - ][ + - ]: 1717 : Append( new FuncData( pFuncDatas[ n ], rResMgr ) );
[ + - ]
1421 : 17 : }
1422 : :
1423 : :
1424 : 7 : FuncDataList::~FuncDataList()
1425 : : {
1426 [ + + ]: 714 : for( FuncData* p = ( FuncData* ) First() ; p ; p = ( FuncData* ) Next() )
1427 [ + - ][ + - ]: 707 : delete p;
1428 [ - + ]: 14 : }
1429 : :
1430 : :
1431 : 15146 : const FuncData* FuncDataList::Get( const OUString& aProgrammaticName ) const
1432 : : {
1433 [ + + ]: 15146 : if( aLastName == aProgrammaticName )
1434 : 13328 : return Get( nLast );
1435 : :
1436 : 1818 : ( ( FuncDataList* ) this )->aLastName = aProgrammaticName;
1437 : :
1438 : 1818 : sal_uInt32 nE = Count();
1439 [ + - ]: 92718 : for( sal_uInt32 n = 0 ; n < nE ; n++ )
1440 : : {
1441 : 92718 : const FuncData* p = Get( n );
1442 [ + + ]: 92718 : if( p->Is( aProgrammaticName ) )
1443 : : {
1444 : 1818 : ( ( FuncDataList* ) this )->nLast = n;
1445 : 1818 : return p;
1446 : : }
1447 : : }
1448 : :
1449 : 0 : ( ( FuncDataList* ) this )->nLast = 0xFFFFFFFF;
1450 : 15146 : return NULL;
1451 : : }
1452 : :
1453 : :
1454 : 41701 : AnalysisResId::AnalysisResId( sal_uInt16 nId, ResMgr& rResMgr ) : ResId( nId, rResMgr )
1455 : : {
1456 : 41701 : }
1457 : :
1458 : :
1459 : :
1460 : :
1461 : 0 : SortedIndividualInt32List::SortedIndividualInt32List()
1462 : : {
1463 : 0 : }
1464 : :
1465 : :
1466 : 0 : SortedIndividualInt32List::~SortedIndividualInt32List()
1467 : : {
1468 [ # # ]: 0 : }
1469 : :
1470 : :
1471 : 0 : void SortedIndividualInt32List::Insert( sal_Int32 nDay )
1472 : : {
1473 : 0 : sal_uInt32 nIndex = Count();
1474 [ # # ]: 0 : while( nIndex )
1475 : : {
1476 : 0 : nIndex--;
1477 : 0 : sal_Int32 nRef = Get( nIndex );
1478 [ # # ]: 0 : if( nDay == nRef )
1479 : 0 : return;
1480 [ # # ]: 0 : else if( nDay > nRef )
1481 : : {
1482 : 0 : MyList::Insert( (void*)(sal_IntPtr)nDay, nIndex + 1 );
1483 : 0 : return;
1484 : : }
1485 : : }
1486 : 0 : MyList::Insert( (void*)(sal_IntPtr)nDay, 0UL );
1487 : : }
1488 : :
1489 : :
1490 : 0 : void SortedIndividualInt32List::Insert( sal_Int32 nDay, sal_Int32 nNullDate, sal_Bool bInsertOnWeekend )
1491 : : {
1492 [ # # ]: 0 : if( !nDay )
1493 : 0 : return;
1494 : :
1495 : 0 : nDay += nNullDate;
1496 [ # # ][ # # ]: 0 : if( bInsertOnWeekend || (GetDayOfWeek( nDay ) < 5) )
[ # # ]
1497 : 0 : Insert( nDay );
1498 : : }
1499 : :
1500 : :
1501 : 0 : void SortedIndividualInt32List::Insert(
1502 : : double fDay, sal_Int32 nNullDate, sal_Bool bInsertOnWeekend ) throw( uno::RuntimeException, lang::IllegalArgumentException )
1503 : : {
1504 [ # # ][ # # ]: 0 : if( (fDay < -2147483648.0) || (fDay > 2147483649.0) )
1505 [ # # ]: 0 : throw lang::IllegalArgumentException();
1506 : 0 : Insert( static_cast< sal_Int32 >( fDay ), nNullDate, bInsertOnWeekend );
1507 : 0 : }
1508 : :
1509 : :
1510 : 0 : sal_Bool SortedIndividualInt32List::Find( sal_Int32 nVal ) const
1511 : : {
1512 : 0 : sal_uInt32 nE = Count();
1513 : :
1514 [ # # ][ # # ]: 0 : if( !nE || nVal < Get( 0 ) || nVal > Get( nE - 1 ) )
[ # # ][ # # ]
1515 : 0 : return sal_False;
1516 : :
1517 : : // linear search
1518 : :
1519 [ # # ]: 0 : for( sal_uInt32 n = 0 ; n < nE ; n++ )
1520 : : {
1521 : 0 : sal_Int32 nRef = Get( n );
1522 : :
1523 [ # # ]: 0 : if( nRef == nVal )
1524 : 0 : return sal_True;
1525 [ # # ]: 0 : else if( nRef > nVal )
1526 : 0 : return sal_False;
1527 : : }
1528 : 0 : return sal_False;
1529 : : }
1530 : :
1531 : :
1532 : 0 : void SortedIndividualInt32List::InsertHolidayList(
1533 : : const ScaAnyConverter& rAnyConv,
1534 : : const uno::Any& rHolAny,
1535 : : sal_Int32 nNullDate,
1536 : : sal_Bool bInsertOnWeekend ) throw( uno::RuntimeException, lang::IllegalArgumentException )
1537 : : {
1538 : : double fDay;
1539 [ # # ][ # # ]: 0 : if( rAnyConv.getDouble( fDay, rHolAny ) )
1540 [ # # ]: 0 : Insert( fDay, nNullDate, bInsertOnWeekend );
1541 : 0 : }
1542 : :
1543 : :
1544 : 0 : void SortedIndividualInt32List::InsertHolidayList(
1545 : : ScaAnyConverter& rAnyConv,
1546 : : const uno::Reference< beans::XPropertySet >& xOptions,
1547 : : const uno::Any& rHolAny,
1548 : : sal_Int32 nNullDate,
1549 : : sal_Bool bInsertOnWeekend ) throw( uno::RuntimeException, lang::IllegalArgumentException )
1550 : : {
1551 : 0 : rAnyConv.init( xOptions );
1552 [ # # ]: 0 : if( rHolAny.getValueTypeClass() == uno::TypeClass_SEQUENCE )
1553 : : {
1554 [ # # ]: 0 : uno::Sequence< uno::Sequence< uno::Any > > aAnySeq;
1555 [ # # ][ # # ]: 0 : if( rHolAny >>= aAnySeq )
1556 : : {
1557 : 0 : const uno::Sequence< uno::Any >* pSeqArray = aAnySeq.getConstArray();
1558 [ # # ]: 0 : for( sal_Int32 nIndex1 = 0; nIndex1 < aAnySeq.getLength(); nIndex1++ )
1559 : : {
1560 : 0 : const uno::Sequence< uno::Any >& rSubSeq = pSeqArray[ nIndex1 ];
1561 : 0 : const uno::Any* pAnyArray = rSubSeq.getConstArray();
1562 : :
1563 [ # # ]: 0 : for( sal_Int32 nIndex2 = 0; nIndex2 < rSubSeq.getLength(); nIndex2++ )
1564 [ # # ]: 0 : InsertHolidayList( rAnyConv, pAnyArray[ nIndex2 ], nNullDate, bInsertOnWeekend );
1565 : : }
1566 : : }
1567 : : else
1568 [ # # ][ # # ]: 0 : throw lang::IllegalArgumentException();
1569 : : }
1570 : : else
1571 : 0 : InsertHolidayList( rAnyConv, rHolAny, nNullDate, bInsertOnWeekend );
1572 : 0 : }
1573 : :
1574 : :
1575 : :
1576 : : //-----------------------------------------------------------------------------
1577 : :
1578 : 0 : ScaDoubleList::~ScaDoubleList()
1579 : : {
1580 [ # # ][ # # ]: 0 : for( double* pDbl = const_cast< double* >( First() ); pDbl; pDbl = const_cast< double* >( Next() ) )
[ # # ]
1581 : 0 : delete pDbl;
1582 [ # # ]: 0 : }
1583 : :
1584 : :
1585 : 0 : void ScaDoubleList::Append(
1586 : : const uno::Sequence< uno::Sequence< double > >& rValueSeq ) throw( uno::RuntimeException, lang::IllegalArgumentException )
1587 : : {
1588 : 0 : const uno::Sequence< double >* pSeqArray = rValueSeq.getConstArray();
1589 [ # # ]: 0 : for( sal_Int32 nIndex1 = 0; nIndex1 < rValueSeq.getLength(); nIndex1++ )
1590 : : {
1591 : 0 : const uno::Sequence< double >& rSubSeq = pSeqArray[ nIndex1 ];
1592 : 0 : const double* pArray = rSubSeq.getConstArray();
1593 [ # # ]: 0 : for( sal_Int32 nIndex2 = 0; nIndex2 < rSubSeq.getLength(); nIndex2++ )
1594 : 0 : Append( pArray[ nIndex2 ] );
1595 : : }
1596 : 0 : }
1597 : :
1598 : :
1599 : 0 : void ScaDoubleList::Append(
1600 : : const uno::Sequence< uno::Sequence< sal_Int32 > >& rValueSeq ) throw( uno::RuntimeException, lang::IllegalArgumentException )
1601 : : {
1602 : 0 : const uno::Sequence< sal_Int32 >* pSeqArray = rValueSeq.getConstArray();
1603 [ # # ]: 0 : for( sal_Int32 nIndex1 = 0; nIndex1 < rValueSeq.getLength(); nIndex1++ )
1604 : : {
1605 : 0 : const uno::Sequence< sal_Int32 >& rSubSeq = pSeqArray[ nIndex1 ];
1606 : 0 : const sal_Int32* pArray = rSubSeq.getConstArray();
1607 [ # # ]: 0 : for( sal_Int32 nIndex2 = 0; nIndex2 < rSubSeq.getLength(); nIndex2++ )
1608 : 0 : Append( pArray[ nIndex2 ] );
1609 : : }
1610 : 0 : }
1611 : :
1612 : :
1613 : :
1614 : 0 : void ScaDoubleList::Append(
1615 : : const ScaAnyConverter& rAnyConv,
1616 : : const uno::Any& rAny,
1617 : : sal_Bool bIgnoreEmpty ) throw( uno::RuntimeException, lang::IllegalArgumentException )
1618 : : {
1619 [ # # ]: 0 : if( rAny.getValueTypeClass() == uno::TypeClass_SEQUENCE )
1620 : 0 : Append( rAnyConv, *static_cast< const uno::Sequence< uno::Sequence< uno::Any > >* >( rAny.getValue() ), bIgnoreEmpty );
1621 : : else
1622 : : {
1623 : : double fValue;
1624 [ # # ][ # # ]: 0 : if( rAnyConv.getDouble( fValue, rAny ) )
1625 [ # # ]: 0 : Append( fValue );
1626 [ # # ]: 0 : else if( !bIgnoreEmpty )
1627 [ # # ]: 0 : Append( 0.0 );
1628 : : }
1629 : 0 : }
1630 : :
1631 : :
1632 : 0 : void ScaDoubleList::Append(
1633 : : const ScaAnyConverter& rAnyConv,
1634 : : const uno::Sequence< uno::Any >& rAnySeq,
1635 : : sal_Bool bIgnoreEmpty ) throw( uno::RuntimeException, lang::IllegalArgumentException )
1636 : : {
1637 : 0 : const uno::Any* pArray = rAnySeq.getConstArray();
1638 [ # # ]: 0 : for( sal_Int32 nIndex = 0; nIndex < rAnySeq.getLength(); nIndex++ )
1639 : 0 : Append( rAnyConv, pArray[ nIndex ], bIgnoreEmpty );
1640 : 0 : }
1641 : :
1642 : :
1643 : 0 : void ScaDoubleList::Append(
1644 : : const ScaAnyConverter& rAnyConv,
1645 : : const uno::Sequence< uno::Sequence< uno::Any > >& rAnySeq,
1646 : : sal_Bool bIgnoreEmpty ) throw( uno::RuntimeException, lang::IllegalArgumentException )
1647 : : {
1648 : 0 : const uno::Sequence< uno::Any >* pArray = rAnySeq.getConstArray();
1649 [ # # ]: 0 : for( sal_Int32 nIndex = 0; nIndex < rAnySeq.getLength(); nIndex++ )
1650 : 0 : Append( rAnyConv, pArray[ nIndex ], bIgnoreEmpty );
1651 : 0 : }
1652 : :
1653 : :
1654 : :
1655 : 0 : void ScaDoubleList::Append(
1656 : : ScaAnyConverter& rAnyConv,
1657 : : const uno::Reference< beans::XPropertySet >& xOpt,
1658 : : const uno::Sequence< uno::Any >& rAnySeq,
1659 : : sal_Bool bIgnoreEmpty ) throw( uno::RuntimeException, lang::IllegalArgumentException )
1660 : : {
1661 : 0 : rAnyConv.init( xOpt );
1662 : 0 : Append( rAnyConv, rAnySeq, bIgnoreEmpty );
1663 : 0 : }
1664 : :
1665 : :
1666 : 0 : sal_Bool ScaDoubleList::CheckInsert( double ) const throw( uno::RuntimeException, lang::IllegalArgumentException )
1667 : : {
1668 : 0 : return sal_True;
1669 : : }
1670 : :
1671 : :
1672 : :
1673 : : //-----------------------------------------------------------------------------
1674 : :
1675 : 0 : sal_Bool ScaDoubleListGT0::CheckInsert( double fValue ) const throw( uno::RuntimeException, lang::IllegalArgumentException )
1676 : : {
1677 [ # # ]: 0 : if( fValue < 0.0 )
1678 [ # # ]: 0 : throw lang::IllegalArgumentException();
1679 : 0 : return fValue > 0.0;
1680 : : }
1681 : :
1682 : :
1683 : :
1684 : : //-----------------------------------------------------------------------------
1685 : :
1686 : 0 : sal_Bool ScaDoubleListGE0::CheckInsert( double fValue ) const throw( uno::RuntimeException, lang::IllegalArgumentException )
1687 : : {
1688 [ # # ]: 0 : if( fValue < 0.0 )
1689 [ # # ]: 0 : throw lang::IllegalArgumentException();
1690 : 0 : return sal_True;
1691 : : }
1692 : :
1693 : :
1694 : :
1695 : : //-----------------------------------------------------------------------------
1696 : :
1697 : 0 : Complex::Complex( const STRING& rStr ) THROWDEF_RTE_IAE
1698 : : {
1699 [ # # ]: 0 : if( !ParseString( rStr, *this ) )
1700 [ # # ]: 0 : THROW_IAE;
1701 : 0 : }
1702 : :
1703 : :
1704 : 0 : inline sal_Bool Complex::IsImagUnit( sal_Unicode c )
1705 : : {
1706 [ # # ][ # # ]: 0 : return c == 'i' || c == 'j';
1707 : : }
1708 : :
1709 : 0 : sal_Bool Complex::ParseString( const STRING& rStr, Complex& rCompl )
1710 : : {
1711 : 0 : rCompl.c = '\0'; // do not force a symbol, if only real part present
1712 : :
1713 : 0 : const sal_Unicode* pStr = rStr.getStr();
1714 : :
1715 [ # # ][ # # ]: 0 : if( IsImagUnit( *pStr ) && rStr.getLength() == 1)
[ # # ]
1716 : : {
1717 : 0 : rCompl.r = 0.0;
1718 : 0 : rCompl.i = 1.0;
1719 : 0 : rCompl.c = *pStr;
1720 : 0 : return sal_True;
1721 : : }
1722 : :
1723 : : double f;
1724 : :
1725 [ # # ]: 0 : if( !ParseDouble( pStr, f ) )
1726 : 0 : return sal_False;
1727 : :
1728 [ # # # # ]: 0 : switch( *pStr )
1729 : : {
1730 : : case '-': // imag part follows
1731 : : case '+':
1732 : : {
1733 : 0 : double r = f;
1734 [ # # ]: 0 : if( IsImagUnit( pStr[ 1 ] ) )
1735 : : {
1736 : 0 : rCompl.c = pStr[ 1 ];
1737 [ # # ]: 0 : if( pStr[ 2 ] == 0 )
1738 : : {
1739 : 0 : rCompl.r = f;
1740 [ # # ]: 0 : rCompl.i = ( *pStr == '+' )? 1.0 : -1.0;
1741 : 0 : return sal_True;
1742 : : }
1743 : : }
1744 [ # # ][ # # ]: 0 : else if( ParseDouble( pStr, f ) && IsImagUnit( *pStr ) )
[ # # ]
1745 : : {
1746 : 0 : rCompl.c = *pStr;
1747 : 0 : pStr++;
1748 [ # # ]: 0 : if( *pStr == 0 )
1749 : : {
1750 : 0 : rCompl.r = r;
1751 : 0 : rCompl.i = f;
1752 : 0 : return sal_True;
1753 : : }
1754 : : }
1755 : : }
1756 : 0 : break;
1757 : : case 'j':
1758 : : case 'i':
1759 : 0 : rCompl.c = *pStr;
1760 : 0 : pStr++;
1761 [ # # ]: 0 : if( *pStr == 0 )
1762 : : {
1763 : 0 : rCompl.i = f;
1764 : 0 : rCompl.r = 0.0;
1765 : 0 : return sal_True;
1766 : : }
1767 : 0 : break;
1768 : : case 0: // only real-part
1769 : 0 : rCompl.r = f;
1770 : 0 : rCompl.i = 0.0;
1771 : 0 : return sal_True;
1772 : : }
1773 : :
1774 : 0 : return sal_False;
1775 : : }
1776 : :
1777 : :
1778 : 0 : STRING Complex::GetString() const THROWDEF_RTE_IAE
1779 : : {
1780 [ # # ][ # # ]: 0 : CHK_FINITE(r);
1781 [ # # ][ # # ]: 0 : CHK_FINITE(i);
1782 : 0 : rtl::OUStringBuffer aRet;
1783 : :
1784 : 0 : bool bHasImag = i != 0.0;
1785 [ # # ][ # # ]: 0 : bool bHasReal = !bHasImag || (r != 0.0);
1786 : :
1787 [ # # ]: 0 : if( bHasReal )
1788 [ # # ][ # # ]: 0 : aRet.append(::GetString( r ));
1789 [ # # ]: 0 : if( bHasImag )
1790 : : {
1791 [ # # ]: 0 : if( i == 1.0 )
1792 : : {
1793 [ # # ]: 0 : if( bHasReal )
1794 [ # # ]: 0 : aRet.append('+');
1795 : : }
1796 [ # # ]: 0 : else if( i == -1.0 )
1797 [ # # ]: 0 : aRet.append('-');
1798 : : else
1799 [ # # ][ # # ]: 0 : aRet.append(::GetString( i, bHasReal ));
1800 [ # # ][ # # ]: 0 : aRet.append((c != 'j') ? 'i' : 'j');
1801 : : }
1802 : :
1803 [ # # ]: 0 : return aRet.makeStringAndClear();
1804 : : }
1805 : :
1806 : :
1807 : 0 : double Complex::Arg( void ) const THROWDEF_RTE_IAE
1808 : : {
1809 [ # # ][ # # ]: 0 : if( r == 0.0 && i == 0.0 )
1810 [ # # ]: 0 : THROW_IAE;
1811 : :
1812 : 0 : double phi = acos( r / Abs() );
1813 : :
1814 [ # # ]: 0 : if( i < 0.0 )
1815 : 0 : phi = -phi;
1816 : :
1817 : 0 : return phi;
1818 : : }
1819 : :
1820 : :
1821 : 0 : void Complex::Power( double fPower ) THROWDEF_RTE_IAE
1822 : : {
1823 [ # # ][ # # ]: 0 : if( r == 0.0 && i == 0.0 )
1824 : : {
1825 [ # # ]: 0 : if( fPower > 0 )
1826 : : {
1827 : 0 : r = i = 0.0;
1828 : 0 : return;
1829 : : }
1830 : : else
1831 [ # # ]: 0 : THROW_IAE;
1832 : : }
1833 : :
1834 : : double p, phi;
1835 : :
1836 : 0 : p = Abs();
1837 : :
1838 : 0 : phi = acos( r / p );
1839 [ # # ]: 0 : if( i < 0.0 )
1840 : 0 : phi = -phi;
1841 : :
1842 : 0 : p = pow( p, fPower );
1843 : 0 : phi *= fPower;
1844 : :
1845 : 0 : r = cos( phi ) * p;
1846 : 0 : i = sin( phi ) * p;
1847 : : }
1848 : :
1849 : :
1850 : 0 : void Complex::Sqrt( void )
1851 : : {
1852 : : static const double fMultConst = 0.7071067811865475; // ...2440084436210485 = 1/sqrt(2)
1853 : 0 : double p = Abs();
1854 : 0 : double i_ = sqrt( p - r ) * fMultConst;
1855 : :
1856 : 0 : r = sqrt( p + r ) * fMultConst;
1857 [ # # ]: 0 : i = ( i < 0.0 )? -i_ : i_;
1858 : 0 : }
1859 : :
1860 : :
1861 : 0 : void Complex::Sin( void ) THROWDEF_RTE_IAE
1862 : : {
1863 [ # # ]: 0 : if( !::rtl::math::isValidArcArg( r ) )
1864 [ # # ]: 0 : THROW_IAE;
1865 : :
1866 [ # # ]: 0 : if( i )
1867 : : {
1868 : : double r_;
1869 : :
1870 : 0 : r_ = sin( r ) * cosh( i );
1871 : 0 : i = cos( r ) * sinh( i );
1872 : 0 : r = r_;
1873 : : }
1874 : : else
1875 : 0 : r = sin( r );
1876 : 0 : }
1877 : :
1878 : :
1879 : 0 : void Complex::Cos( void ) THROWDEF_RTE_IAE
1880 : : {
1881 [ # # ]: 0 : if( !::rtl::math::isValidArcArg( r ) )
1882 [ # # ]: 0 : THROW_IAE;
1883 : :
1884 [ # # ]: 0 : if( i )
1885 : : {
1886 : : double r_;
1887 : :
1888 : 0 : r_ = cos( r ) * cosh( i );
1889 : 0 : i = -( sin( r ) * sinh( i ) );
1890 : 0 : r = r_;
1891 : : }
1892 : : else
1893 : 0 : r = cos( r );
1894 : 0 : }
1895 : :
1896 : :
1897 : 0 : void Complex::Div( const Complex& z ) THROWDEF_RTE_IAE
1898 : : {
1899 [ # # ][ # # ]: 0 : if( z.r == 0 && z.i == 0 )
1900 [ # # ]: 0 : THROW_IAE;
1901 : :
1902 : 0 : double a1 = r;
1903 : 0 : double a2 = z.r;
1904 : 0 : double b1 = i;
1905 : 0 : double b2 = z.i;
1906 : :
1907 : 0 : double f = 1.0 / ( a2 * a2 + b2 * b2 );
1908 : :
1909 : 0 : r = ( a1 * a2 + b1 * b2 ) * f;
1910 : 0 : i = ( a2 * b1 - a1 * b2 ) * f;
1911 : :
1912 [ # # ]: 0 : if( !c ) c = z.c;
1913 : 0 : }
1914 : :
1915 : :
1916 : 0 : void Complex::Exp( void )
1917 : : {
1918 : 0 : double fE = exp( r );
1919 : 0 : r = fE * cos( i );
1920 : 0 : i = fE * sin( i );
1921 : 0 : }
1922 : :
1923 : :
1924 : 0 : void Complex::Ln( void ) THROWDEF_RTE_IAE
1925 : : {
1926 [ # # ][ # # ]: 0 : if( r == 0.0 && i == 0.0 )
1927 [ # # ]: 0 : THROW_IAE;
1928 : :
1929 : 0 : double fAbs = Abs();
1930 : 0 : sal_Bool bNegi = i < 0.0;
1931 : :
1932 : 0 : i = acos( r / fAbs );
1933 : :
1934 [ # # ]: 0 : if( bNegi )
1935 : 0 : i = -i;
1936 : :
1937 : 0 : r = log( fAbs );
1938 : 0 : }
1939 : :
1940 : :
1941 : 0 : void Complex::Log10( void ) THROWDEF_RTE_IAE
1942 : : {
1943 : 0 : Ln();
1944 : 0 : Mult( 0.434294481903251828 ); // * log10( e )
1945 : 0 : }
1946 : :
1947 : :
1948 : 0 : void Complex::Log2( void ) THROWDEF_RTE_IAE
1949 : : {
1950 : 0 : Ln();
1951 : 0 : Mult( 1.442695040888963407 ); // * log2( e )
1952 : 0 : }
1953 : :
1954 : :
1955 : 0 : void Complex::Tan(void) THROWDEF_RTE_IAE
1956 : : {
1957 [ # # ]: 0 : if ( i )
1958 : : {
1959 [ # # ]: 0 : if( !::rtl::math::isValidArcArg( 2.0 * r ) )
1960 [ # # ]: 0 : THROW_IAE;
1961 : 0 : double fScale =1.0 / ( cos( 2.0 * r ) + cosh( 2.0 * i ));
1962 : 0 : r = sin( 2.0 * r ) * fScale;
1963 : 0 : i = sinh( 2.0 * i ) * fScale;
1964 : : }
1965 : : else
1966 : : {
1967 [ # # ]: 0 : if( !::rtl::math::isValidArcArg( r ) )
1968 [ # # ]: 0 : THROW_IAE;
1969 : 0 : r = tan( r );
1970 : : }
1971 : 0 : }
1972 : :
1973 : :
1974 : 0 : void Complex::Sec( void ) THROWDEF_RTE_IAE
1975 : : {
1976 [ # # ]: 0 : if( i )
1977 : : {
1978 [ # # ]: 0 : if( !::rtl::math::isValidArcArg( 2 * r ) )
1979 [ # # ]: 0 : THROW_IAE;
1980 : 0 : double fScale = 1.0 / (cosh( 2.0 * i) + cos ( 2.0 * r));
1981 : : double r_;
1982 : 0 : r_ = 2.0 * cos( r ) * cosh( i ) * fScale;
1983 : 0 : i = 2.0 * sin( r ) * sinh( i ) * fScale;
1984 : 0 : r = r_;
1985 : : }
1986 : : else
1987 : : {
1988 [ # # ]: 0 : if( !::rtl::math::isValidArcArg( r ) )
1989 [ # # ]: 0 : THROW_IAE;
1990 : 0 : r = 1.0 / cos( r );
1991 : : }
1992 : 0 : }
1993 : :
1994 : :
1995 : 0 : void Complex::Csc( void ) THROWDEF_RTE_IAE
1996 : : {
1997 [ # # ]: 0 : if( i )
1998 : : {
1999 [ # # ]: 0 : if( !::rtl::math::isValidArcArg( 2 * r ) )
2000 [ # # ]: 0 : THROW_IAE;
2001 : 0 : double fScale = 1.0 / (cosh( 2.0 * i) - cos ( 2.0 * r));
2002 : : double r_;
2003 : 0 : r_ = 2.0 * sin( r ) * cosh( i ) * fScale;
2004 : 0 : i = -2.0 * cos( r ) * sinh( i ) * fScale;
2005 : 0 : r = r_;
2006 : : }
2007 : : else
2008 : : {
2009 [ # # ]: 0 : if( !::rtl::math::isValidArcArg( r ) )
2010 [ # # ]: 0 : THROW_IAE;
2011 : 0 : r = 1.0 / sin( r );
2012 : : }
2013 : 0 : }
2014 : :
2015 : :
2016 : 0 : void Complex::Cot(void) THROWDEF_RTE_IAE
2017 : : {
2018 [ # # ]: 0 : if ( i )
2019 : : {
2020 [ # # ]: 0 : if( !::rtl::math::isValidArcArg( 2.0 * r ) )
2021 [ # # ]: 0 : THROW_IAE;
2022 : 0 : double fScale =1.0 / ( cosh( 2.0 * i ) - cos( 2.0 * r ) );
2023 : 0 : r = sin( 2.0 * r ) * fScale;
2024 : 0 : i = - ( sinh( 2.0 * i ) * fScale );
2025 : : }
2026 : : else
2027 : : {
2028 [ # # ]: 0 : if( !::rtl::math::isValidArcArg( r ) )
2029 [ # # ]: 0 : THROW_IAE;
2030 : 0 : r = 1.0 / tan( r );
2031 : : }
2032 : 0 : }
2033 : :
2034 : :
2035 : 0 : void Complex::Sinh( void ) THROWDEF_RTE_IAE
2036 : : {
2037 [ # # ]: 0 : if( !::rtl::math::isValidArcArg( r ) )
2038 [ # # ]: 0 : THROW_IAE;
2039 : :
2040 [ # # ]: 0 : if( i )
2041 : : {
2042 : : double r_;
2043 : 0 : r_ = sinh( r ) * cos( i );
2044 : 0 : i = cosh( r ) * sin( i );
2045 : 0 : r = r_;
2046 : : }
2047 : : else
2048 : 0 : r = sinh( r );
2049 : 0 : }
2050 : :
2051 : :
2052 : 0 : void Complex::Cosh( void ) THROWDEF_RTE_IAE
2053 : : {
2054 [ # # ]: 0 : if( !::rtl::math::isValidArcArg( r ) )
2055 [ # # ]: 0 : THROW_IAE;
2056 : :
2057 [ # # ]: 0 : if( i )
2058 : : {
2059 : : double r_;
2060 : 0 : r_ = cosh( r ) * cos( i );
2061 : 0 : i = sinh( r ) * sin( i );
2062 : 0 : r = r_;
2063 : : }
2064 : : else
2065 : 0 : r = cosh( r );
2066 : 0 : }
2067 : :
2068 : :
2069 : 0 : void Complex::Sech(void) THROWDEF_RTE_IAE
2070 : : {
2071 [ # # ]: 0 : if ( i )
2072 : : {
2073 [ # # ]: 0 : if( !::rtl::math::isValidArcArg( 2.0 * r ) )
2074 [ # # ]: 0 : THROW_IAE;
2075 : 0 : double fScale =1.0 / ( cosh( 2.0 * r ) + cos( 2.0 * i ));
2076 : : double r_;
2077 : 0 : r_ = 2.0 * cosh( 2.0 * r ) * cos( i ) * fScale;
2078 : 0 : i = - (2.0 * sinh( 2.0 * r ) * sin( i ) * fScale );
2079 : 0 : r = r_ ;
2080 : : }
2081 : : else
2082 : : {
2083 [ # # ]: 0 : if( !::rtl::math::isValidArcArg( r ) )
2084 [ # # ]: 0 : THROW_IAE;
2085 : 0 : r = 1.0 / cosh( r );
2086 : : }
2087 : 0 : }
2088 : :
2089 : :
2090 : 0 : void Complex::Csch(void) THROWDEF_RTE_IAE
2091 : : {
2092 [ # # ]: 0 : if ( i )
2093 : : {
2094 [ # # ]: 0 : if( !::rtl::math::isValidArcArg( 2.0 * r ) )
2095 [ # # ]: 0 : THROW_IAE;
2096 : 0 : double fScale =1.0 / ( cosh( 2.0 * r ) - cos( 2.0 * i ));
2097 : : double r_;
2098 : 0 : r_ = 2.0 * sinh( 2.0 * r ) * cos( i ) * fScale;
2099 : 0 : i = - ( 2.0 * cosh( 2.0 * r ) * sin( i ) * fScale );
2100 : 0 : r = r_ ;
2101 : : }
2102 : : else
2103 : : {
2104 [ # # ]: 0 : if( !::rtl::math::isValidArcArg( r ) )
2105 [ # # ]: 0 : THROW_IAE;
2106 : 0 : r = 1.0 / sinh( r );
2107 : : }
2108 : 0 : }
2109 : :
2110 : :
2111 : 0 : ComplexList::~ComplexList()
2112 : : {
2113 [ # # ]: 0 : for( Complex* p = ( Complex* ) First() ; p ; p = ( Complex* ) Next() )
2114 : 0 : delete p;
2115 [ # # ]: 0 : }
2116 : :
2117 : :
2118 : 0 : void ComplexList::Append( const SEQSEQ( STRING )& r, ComplListAppendHandl eAH ) THROWDEF_RTE_IAE
2119 : : {
2120 : : sal_Int32 n1, n2;
2121 : 0 : sal_Int32 nE1 = r.getLength();
2122 : : sal_Int32 nE2;
2123 : 0 : sal_Bool bEmpty0 = eAH == AH_EmpyAs0;
2124 : 0 : sal_Bool bErrOnEmpty = eAH == AH_EmptyAsErr;
2125 : :
2126 [ # # ]: 0 : for( n1 = 0 ; n1 < nE1 ; n1++ )
2127 : : {
2128 : 0 : const SEQ( STRING )& rList = r[ n1 ];
2129 : 0 : nE2 = rList.getLength();
2130 : :
2131 [ # # ]: 0 : for( n2 = 0 ; n2 < nE2 ; n2++ )
2132 : : {
2133 : 0 : const STRING& rStr = rList[ n2 ];
2134 : :
2135 [ # # ]: 0 : if( !rStr.isEmpty() )
2136 [ # # ]: 0 : Append( new Complex( rStr ) );
2137 [ # # ]: 0 : else if( bEmpty0 )
2138 : 0 : Append( new Complex( 0.0 ) );
2139 [ # # ]: 0 : else if( bErrOnEmpty )
2140 [ # # ]: 0 : THROW_IAE;
2141 : : }
2142 : : }
2143 : 0 : }
2144 : :
2145 : :
2146 : 0 : void ComplexList::Append( const SEQ( ANY )& aMultPars, ComplListAppendHandl eAH ) THROWDEF_RTE_IAE
2147 : : {
2148 : 0 : sal_Int32 nEle = aMultPars.getLength();
2149 : 0 : sal_Bool bEmpty0 = eAH == AH_EmpyAs0;
2150 : 0 : sal_Bool bErrOnEmpty = eAH == AH_EmptyAsErr;
2151 : :
2152 [ # # ]: 0 : for( sal_Int32 i = 0 ; i < nEle ; i++ )
2153 : : {
2154 : 0 : const ANY& r = aMultPars[ i ];
2155 [ # # # # : 0 : switch( r.getValueTypeClass() )
# ]
2156 : : {
2157 : 0 : case uno::TypeClass_VOID: break;
2158 : : case uno::TypeClass_STRING:
2159 : : {
2160 : 0 : const STRING* pStr = ( const STRING* ) r.getValue();
2161 : :
2162 [ # # ]: 0 : if( !pStr->isEmpty() )
2163 [ # # ]: 0 : Append( new Complex( *( STRING* ) r.getValue() ) );
2164 [ # # ]: 0 : else if( bEmpty0 )
2165 : 0 : Append( new Complex( 0.0 ) );
2166 [ # # ]: 0 : else if( bErrOnEmpty )
2167 [ # # ]: 0 : THROW_IAE;
2168 : : }
2169 : 0 : break;
2170 : : case uno::TypeClass_DOUBLE:
2171 : 0 : Append( new Complex( *( double* ) r.getValue(), 0.0 ) );
2172 : 0 : break;
2173 : : case uno::TypeClass_SEQUENCE:
2174 : : {
2175 [ # # ]: 0 : SEQSEQ( ANY ) aValArr;
2176 [ # # ][ # # ]: 0 : if( r >>= aValArr )
2177 : : {
2178 : 0 : sal_Int32 nE = aValArr.getLength();
2179 : 0 : const SEQ( ANY )* pArr = aValArr.getConstArray();
2180 [ # # ]: 0 : for( sal_Int32 n = 0 ; n < nE ; n++ )
2181 [ # # ]: 0 : Append( pArr[ n ], eAH );
2182 : : }
2183 : : else
2184 [ # # ][ # # ]: 0 : THROW_IAE;
2185 : : }
2186 : 0 : break;
2187 : : default:
2188 [ # # ]: 0 : THROW_IAE;
2189 : : }
2190 : : }
2191 : 0 : }
2192 : :
2193 : :
2194 : :
2195 : :
2196 : 0 : ConvertData::ConvertData( const sal_Char p[], double fC, ConvertDataClass e, sal_Bool bPrefSupport ) : aName( p, strlen( p ), RTL_TEXTENCODING_MS_1252 )
2197 : : {
2198 : 0 : fConst = fC;
2199 : 0 : eClass = e;
2200 : 0 : bPrefixSupport = bPrefSupport;
2201 : 0 : }
2202 : :
2203 : 0 : ConvertData::~ConvertData()
2204 : : {
2205 [ # # ]: 0 : }
2206 : :
2207 : :
2208 : 0 : sal_Int16 ConvertData::GetMatchingLevel( const STRING& rRef ) const
2209 : : {
2210 : 0 : STRING aStr = rRef;
2211 : 0 : sal_Int32 nLen = rRef.getLength();
2212 : 0 : sal_Int32 nIndex = rRef.lastIndexOf( '^' );
2213 [ # # ][ # # ]: 0 : if( nIndex > 0 && nIndex == ( nLen - 2 ) )
2214 : : {
2215 : 0 : const sal_Unicode* p = aStr.getStr();
2216 : 0 : aStr = STRING( p, nLen - 2 );
2217 : 0 : aStr += STRING( p[ nLen - 1 ] );
2218 : : }
2219 [ # # ]: 0 : if( aName.equals( aStr ) )
2220 : 0 : return 0;
2221 : : else
2222 : : {
2223 : 0 : const sal_Unicode* p = aStr.getStr();
2224 : :
2225 : 0 : nLen = aStr.getLength();
2226 : 0 : bool bPref = IsPrefixSupport();
2227 [ # # ][ # # ]: 0 : bool bOneChar = (bPref && nLen > 1 && (aName == p + 1));
[ # # ]
2228 [ # # ][ # # ]: 0 : if (bOneChar || (bPref && nLen > 2 && (aName == p + 2) &&
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
2229 : 0 : *p == 'd' && *(p+1) == 'a'))
2230 : : {
2231 : : sal_Int16 n;
2232 [ # # # # : 0 : switch( *p )
# # # # #
# # # # #
# # # # #
# # ]
2233 : : {
2234 : 0 : case 'y': n = -24; break; // yocto
2235 : 0 : case 'z': n = -21; break; // zepto
2236 : 0 : case 'a': n = -18; break;
2237 : 0 : case 'f': n = -15; break;
2238 : 0 : case 'p': n = -12; break;
2239 : 0 : case 'n': n = -9; break;
2240 : 0 : case 'u': n = -6; break;
2241 : 0 : case 'm': n = -3; break;
2242 : 0 : case 'c': n = -2; break;
2243 : : case 'd':
2244 : : {
2245 [ # # ]: 0 : if ( bOneChar )
2246 : 0 : n = -1; // deci
2247 : : else
2248 : 0 : n = 1; // deca
2249 : : }
2250 : 0 : break;
2251 : 0 : case 'e': n = 1; break;
2252 : 0 : case 'h': n = 2; break;
2253 : 0 : case 'k': n = 3; break;
2254 : 0 : case 'M': n = 6; break;
2255 : 0 : case 'G': n = 9; break;
2256 : 0 : case 'T': n = 12; break;
2257 : 0 : case 'P': n = 15; break;
2258 : 0 : case 'E': n = 18; break;
2259 : 0 : case 'Z': n = 21; break; // zetta
2260 : 0 : case 'Y': n = 24; break; // yotta
2261 : : default:
2262 : 0 : n = INV_MATCHLEV;
2263 : : }
2264 : :
2265 : : // We could weed some nonsense out, ODFF doesn't say so though.
2266 : : #if 0
2267 : : if (n < 0 && Class() == CDC_Information)
2268 : : n = INV_MATCHLEV; // milli-bits doesn't make sense
2269 : : #endif
2270 : :
2271 : : //! <HACK> "cm3" is not 10^-2 m^3 but 10^-6 m^3 !!! ------------------
2272 [ # # ]: 0 : if( n != INV_MATCHLEV )
2273 : : {
2274 : 0 : sal_Unicode cLast = p[ aStr.getLength() - 1 ];
2275 [ # # ]: 0 : if( cLast == '2' )
2276 : 0 : n *= 2;
2277 [ # # ]: 0 : else if( cLast == '3' )
2278 : 0 : n *= 3;
2279 : : }
2280 : : //! </HACK> -------------------------------------------------------------------
2281 : :
2282 : 0 : return n;
2283 : : }
2284 [ # # ][ # # ]: 0 : else if ( nLen > 2 && ( aName == p + 2 ) && ( Class() == CDC_Information ) )
[ # # ][ # # ]
2285 : : {
2286 : 0 : const sal_Unicode* pStr = aStr.getStr();
2287 [ # # ]: 0 : if ( *(pStr + 1) != 'i')
2288 : 0 : return INV_MATCHLEV;
2289 : : sal_Int16 n;
2290 [ # # # # : 0 : switch( *pStr )
# # # #
# ]
2291 : : {
2292 : 0 : case 'k': n = 10; break;
2293 : 0 : case 'M': n = 20; break;
2294 : 0 : case 'G': n = 30; break;
2295 : 0 : case 'T': n = 40; break;
2296 : 0 : case 'P': n = 50; break;
2297 : 0 : case 'E': n = 60; break;
2298 : 0 : case 'Z': n = 70; break;
2299 : 0 : case 'Y': n = 80; break;
2300 : : default:
2301 : 0 : n = INV_MATCHLEV;
2302 : : }
2303 : 0 : return n;
2304 : : }
2305 : : else
2306 : 0 : return INV_MATCHLEV;
2307 : 0 : }
2308 : : }
2309 : :
2310 : :
2311 : 0 : double ConvertData::Convert(
2312 : : double f, const ConvertData& r, sal_Int16 nLevFrom, sal_Int16 nLevTo ) const THROWDEF_RTE_IAE
2313 : : {
2314 [ # # ]: 0 : if( Class() != r.Class() )
2315 [ # # ]: 0 : THROW_IAE;
2316 : :
2317 [ # # ][ # # ]: 0 : sal_Bool bBinFromLev = ( nLevFrom > 0 && ( nLevFrom % 10 ) == 0 );
2318 [ # # ][ # # ]: 0 : sal_Bool bBinToLev = ( nLevTo > 0 && ( nLevTo % 10 ) == 0 );
2319 : :
2320 [ # # ][ # # ]: 0 : if ( Class() == CDC_Information && ( bBinFromLev || bBinToLev ) )
[ # # ][ # # ]
2321 : : {
2322 [ # # ][ # # ]: 0 : if ( bBinFromLev && bBinToLev )
2323 : : {
2324 : 0 : nLevFrom = sal::static_int_cast<sal_Int16>( nLevFrom - nLevTo );
2325 : 0 : f *= r.fConst / fConst;
2326 [ # # ]: 0 : if( nLevFrom )
2327 : 0 : f *= pow( 2.0, nLevFrom );
2328 : : }
2329 [ # # ]: 0 : else if ( bBinFromLev )
2330 : 0 : f *= ( r.fConst / fConst ) * ( pow( 2.0, nLevFrom ) / pow( 10.0, nLevTo ) );
2331 : : else
2332 : 0 : f *= ( r.fConst / fConst ) * ( pow( 10.0, nLevFrom ) / pow( 2.0, nLevTo ) );
2333 : 0 : return f;
2334 : : }
2335 : :
2336 : 0 : nLevFrom = sal::static_int_cast<sal_Int16>( nLevFrom - nLevTo ); // effective level
2337 : :
2338 : 0 : f *= r.fConst / fConst;
2339 : :
2340 [ # # ]: 0 : if( nLevFrom )
2341 : 0 : f = ::rtl::math::pow10Exp( f, nLevFrom );
2342 : :
2343 : 0 : return f;
2344 : : }
2345 : :
2346 : :
2347 : 0 : double ConvertData::ConvertToBase( double f, sal_Int16 n ) const
2348 : : {
2349 : 0 : return ::rtl::math::pow10Exp( f / fConst, n );
2350 : : }
2351 : :
2352 : :
2353 : 0 : double ConvertData::ConvertFromBase( double f, sal_Int16 n ) const
2354 : : {
2355 : 0 : return ::rtl::math::pow10Exp( f * fConst, -n );
2356 : : }
2357 : :
2358 : :
2359 : :
2360 : 0 : ConvertDataLinear::~ConvertDataLinear()
2361 : : {
2362 [ # # ]: 0 : }
2363 : :
2364 : 0 : double ConvertDataLinear::Convert(
2365 : : double f, const ConvertData& r, sal_Int16 nLevFrom, sal_Int16 nLevTo ) const THROWDEF_RTE_IAE
2366 : : {
2367 [ # # ]: 0 : if( Class() != r.Class() )
2368 [ # # ]: 0 : THROW_IAE;
2369 : 0 : return r.ConvertFromBase( ConvertToBase( f, nLevFrom ), nLevTo );
2370 : : }
2371 : :
2372 : :
2373 : 0 : double ConvertDataLinear::ConvertToBase( double f, sal_Int16 n ) const
2374 : : {
2375 [ # # ]: 0 : if( n )
2376 : 0 : f = ::rtl::math::pow10Exp( f, n );
2377 : :
2378 : 0 : f /= fConst;
2379 : 0 : f -= fOffs;
2380 : :
2381 : 0 : return f;
2382 : : }
2383 : :
2384 : :
2385 : 0 : double ConvertDataLinear::ConvertFromBase( double f, sal_Int16 n ) const
2386 : : {
2387 : 0 : f += fOffs;
2388 : 0 : f *= fConst;
2389 : :
2390 [ # # ]: 0 : if( n )
2391 : 0 : f = ::rtl::math::pow10Exp( f, -n );
2392 : :
2393 : 0 : return f;
2394 : : }
2395 : :
2396 : :
2397 : :
2398 : :
2399 : 0 : ConvertDataList::ConvertDataList( void )
2400 : : {
2401 : : #define NEWD(str,unit,cl) Append(new ConvertData(str,unit,cl))
2402 : : #define NEWDP(str,unit,cl) Append(new ConvertData(str,unit,cl,sal_True))
2403 : : #define NEWL(str,unit,offs,cl) Append(new ConvertDataLinear(str,unit,offs,cl))
2404 : : #define NEWLP(str,unit,offs,cl) Append(new ConvertDataLinear(str,unit,offs,cl,sal_True))
2405 : :
2406 : : // *** are extra and not standard Excel Analysis Addin!
2407 : :
2408 : : // MASS: 1 Gram is...
2409 [ # # ][ # # ]: 0 : NEWDP( "g", 1.0000000000000000E00, CDC_Mass ); // Gram
[ # # ]
2410 [ # # ][ # # ]: 0 : NEWD( "sg", 6.8522050005347800E-05, CDC_Mass ); // Pieces
[ # # ]
2411 [ # # ][ # # ]: 0 : NEWD( "lbm", 2.2046229146913400E-03, CDC_Mass ); // Pound (commercial weight)
[ # # ]
2412 [ # # ][ # # ]: 0 : NEWDP( "u", 6.0221370000000000E23, CDC_Mass ); // U (atomic mass)
[ # # ]
2413 [ # # ][ # # ]: 0 : NEWD( "ozm", 3.5273971800362700E-02, CDC_Mass ); // Ounce (commercial weight)
[ # # ]
2414 [ # # ][ # # ]: 0 : NEWD( "stone", 1.574730e-04, CDC_Mass ); // *** Stone
[ # # ]
2415 [ # # ][ # # ]: 0 : NEWD( "ton", 1.102311e-06, CDC_Mass ); // *** Ton
[ # # ]
2416 [ # # ][ # # ]: 0 : NEWD( "grain", 1.543236E01, CDC_Mass ); // *** Grain
[ # # ]
2417 [ # # ][ # # ]: 0 : NEWD( "pweight", 7.054792E-01, CDC_Mass ); // *** Pennyweight
[ # # ]
2418 [ # # ][ # # ]: 0 : NEWD( "hweight", 1.968413E-05, CDC_Mass ); // *** Hundredweight
[ # # ]
2419 [ # # ][ # # ]: 0 : NEWD( "shweight", 2.204623E-05, CDC_Mass ); // *** Shorthundredweight
[ # # ]
2420 [ # # ][ # # ]: 0 : NEWD( "brton", 9.842065E-07, CDC_Mass ); // *** Gross Registered Ton
[ # # ]
2421 [ # # ][ # # ]: 0 : NEWD( "cwt", 2.2046226218487758E-05, CDC_Mass ); // U.S. (short) hundredweight
[ # # ]
2422 [ # # ][ # # ]: 0 : NEWD( "shweight", 2.2046226218487758E-05, CDC_Mass ); // U.S. (short) hundredweight also
[ # # ]
2423 [ # # ][ # # ]: 0 : NEWD( "uk_cwt", 1.9684130552221213E-05, CDC_Mass ); // Imperial hundredweight
[ # # ]
2424 [ # # ][ # # ]: 0 : NEWD( "lcwt", 1.9684130552221213E-05, CDC_Mass ); // Imperial hundredweight also
[ # # ]
2425 [ # # ][ # # ]: 0 : NEWD( "hweight", 1.9684130552221213E-05, CDC_Mass ); // Imperial hundredweight also
[ # # ]
2426 [ # # ][ # # ]: 0 : NEWD( "uk_ton", 9.8420652761106063E-07, CDC_Mass ); // Imperial ton
[ # # ]
2427 [ # # ][ # # ]: 0 : NEWD( "LTON", 9.8420652761106063E-07, CDC_Mass ); // Imperial ton also
[ # # ]
2428 : :
2429 : : // LENGTH: 1 Meter is...
2430 [ # # ][ # # ]: 0 : NEWDP( "m", 1.0000000000000000E00, CDC_Length ); // Meter
[ # # ]
2431 [ # # ][ # # ]: 0 : NEWD( "mi", 6.2137119223733397E-04, CDC_Length ); // Britsh Mile 6,21371192237333969617434184363e-4
[ # # ]
2432 [ # # ][ # # ]: 0 : NEWD( "Nmi", 5.3995680345572354E-04, CDC_Length ); // Nautical Mile 5,39956803455723542116630669546e-4
[ # # ]
2433 [ # # ][ # # ]: 0 : NEWD( "in", 3.9370078740157480E01, CDC_Length ); // Inch 39,37007874015748031496062992126
[ # # ]
2434 [ # # ][ # # ]: 0 : NEWD( "ft", 3.2808398950131234E00, CDC_Length ); // Foot 3,2808398950131233595800524934383
[ # # ]
2435 [ # # ][ # # ]: 0 : NEWD( "yd", 1.0936132983377078E00, CDC_Length ); // Yard 1,0936132983377077865266841644794
[ # # ]
2436 [ # # ][ # # ]: 0 : NEWDP( "ang", 1.0000000000000000E10, CDC_Length ); // Angstroem
[ # # ]
2437 [ # # ][ # # ]: 0 : NEWD( "Pica", 2.8346456692913386E03, CDC_Length ); // Pica (1/72 Inch) 2834,6456692913385826771653543307
[ # # ]
2438 [ # # ][ # # ]: 0 : NEWD( "ell", 8.748906E-01, CDC_Length ); // *** Ell
[ # # ]
2439 [ # # ][ # # ]: 0 : NEWDP( "parsec", 3.240779E-17, CDC_Length ); // *** Parsec
[ # # ]
2440 [ # # ][ # # ]: 0 : NEWDP( "pc", 3.240779E-17, CDC_Length ); // *** Parsec also
[ # # ]
2441 [ # # ][ # # ]: 0 : NEWDP( "lightyear", 1.0570234557732930E-16, CDC_Length ); // *** Light Year
[ # # ]
2442 [ # # ][ # # ]: 0 : NEWDP( "ly", 1.0570234557732930E-16, CDC_Length ); // *** Light Year also
[ # # ]
2443 [ # # ][ # # ]: 0 : NEWD( "survey_mi", 6.2136994949494949E-04, CDC_Length ); // U.S. survey mile
[ # # ]
2444 : :
2445 : : // TIME: 1 Second is...
2446 [ # # ][ # # ]: 0 : NEWD( "yr", 3.1688087814028950E-08, CDC_Time ); // Year
[ # # ]
2447 [ # # ][ # # ]: 0 : NEWD( "day", 1.1574074074074074E-05, CDC_Time ); // Day
[ # # ]
2448 [ # # ][ # # ]: 0 : NEWD( "d", 1.1574074074074074E-05, CDC_Time ); // Day also
[ # # ]
2449 [ # # ][ # # ]: 0 : NEWD( "hr", 2.7777777777777778E-04, CDC_Time ); // Hour
[ # # ]
2450 [ # # ][ # # ]: 0 : NEWD( "mn", 1.6666666666666667E-02, CDC_Time ); // Minute
[ # # ]
2451 [ # # ][ # # ]: 0 : NEWD( "min", 1.6666666666666667E-02, CDC_Time ); // Minute also
[ # # ]
2452 [ # # ][ # # ]: 0 : NEWDP( "sec", 1.0000000000000000E00, CDC_Time ); // Second
[ # # ]
2453 [ # # ][ # # ]: 0 : NEWDP( "s", 1.0000000000000000E00, CDC_Time ); // Second also
[ # # ]
2454 : :
2455 : : // PRESSURE: 1 Pascal is...
2456 [ # # ][ # # ]: 0 : NEWDP( "Pa", 1.0000000000000000E00, CDC_Pressure ); // Pascal
[ # # ]
2457 [ # # ][ # # ]: 0 : NEWDP( "atm", 9.8692329999819300E-06, CDC_Pressure ); // Atmosphere
[ # # ]
2458 [ # # ][ # # ]: 0 : NEWDP( "at", 9.8692329999819300E-06, CDC_Pressure ); // Atmosphere also
[ # # ]
2459 [ # # ][ # # ]: 0 : NEWDP( "mmHg", 7.5006170799862700E-03, CDC_Pressure ); // mm Hg (Mercury)
[ # # ]
2460 [ # # ][ # # ]: 0 : NEWD( "Torr", 7.5006380000000000E-03, CDC_Pressure ); // *** Torr
[ # # ]
2461 [ # # ][ # # ]: 0 : NEWD( "psi", 1.4503770000000000E-04, CDC_Pressure ); // *** Psi
[ # # ]
2462 : :
2463 : : // FORCE: 1 Newton is...
2464 [ # # ][ # # ]: 0 : NEWDP( "N", 1.0000000000000000E00, CDC_Force ); // Newton
[ # # ]
2465 [ # # ][ # # ]: 0 : NEWDP( "dyn", 1.0000000000000000E05, CDC_Force ); // Dyn
[ # # ]
2466 [ # # ][ # # ]: 0 : NEWDP( "dy", 1.0000000000000000E05, CDC_Force ); // Dyn also
[ # # ]
2467 [ # # ][ # # ]: 0 : NEWD( "lbf", 2.24808923655339E-01, CDC_Force ); // Pound-Force
[ # # ]
2468 [ # # ][ # # ]: 0 : NEWDP( "pond", 1.019716E02, CDC_Force ); // *** Pond
[ # # ]
2469 : :
2470 : : // ENERGY: 1 Joule is...
2471 [ # # ][ # # ]: 0 : NEWDP( "J", 1.0000000000000000E00, CDC_Energy ); // Joule
[ # # ]
2472 [ # # ][ # # ]: 0 : NEWDP( "e", 1.0000000000000000E07, CDC_Energy ); // Erg -> http://www.chemie.fu-berlin.de/chemistry/general/si.html
[ # # ]
2473 [ # # ][ # # ]: 0 : NEWDP( "c", 2.3900624947346700E-01, CDC_Energy ); // Thermodynamical Calorie
[ # # ]
2474 [ # # ][ # # ]: 0 : NEWDP( "cal", 2.3884619064201700E-01, CDC_Energy ); // Calorie
[ # # ]
2475 [ # # ][ # # ]: 0 : NEWDP( "eV", 6.2414570000000000E18, CDC_Energy ); // Electronvolt
[ # # ]
2476 [ # # ][ # # ]: 0 : NEWDP( "ev", 6.2414570000000000E18, CDC_Energy ); // Electronvolt also
[ # # ]
2477 [ # # ][ # # ]: 0 : NEWD( "HPh", 3.7250611111111111E-07, CDC_Energy ); // Horsepower Hours
[ # # ]
2478 [ # # ][ # # ]: 0 : NEWD( "hh", 3.7250611111111111E-07, CDC_Energy ); // Horsepower Hours also
[ # # ]
2479 [ # # ][ # # ]: 0 : NEWDP( "Wh", 2.7777777777777778E-04, CDC_Energy ); // Watt Hours
[ # # ]
2480 [ # # ][ # # ]: 0 : NEWDP( "wh", 2.7777777777777778E-04, CDC_Energy ); // Watt Hours also
[ # # ]
2481 [ # # ][ # # ]: 0 : NEWD( "flb", 2.37304222192651E01, CDC_Energy ); // Foot Pound
[ # # ]
2482 [ # # ][ # # ]: 0 : NEWD( "BTU", 9.4781506734901500E-04, CDC_Energy ); // British Thermal Unit
[ # # ]
2483 [ # # ][ # # ]: 0 : NEWD( "btu", 9.4781506734901500E-04, CDC_Energy ); // British Thermal Unit also
[ # # ]
2484 : :
2485 : : // POWER: 1 Watt is...
2486 [ # # ][ # # ]: 0 : NEWDP( "W", 1.0000000000000000E00, CDC_Power ); // Watt
[ # # ]
2487 [ # # ][ # # ]: 0 : NEWDP( "w", 1.0000000000000000E00, CDC_Power ); // Watt also
[ # # ]
2488 [ # # ][ # # ]: 0 : NEWD( "HP", 1.341022E-03, CDC_Power ); // Horsepower
[ # # ]
2489 [ # # ][ # # ]: 0 : NEWD( "h", 1.341022E-03, CDC_Power ); // Horsepower also
[ # # ]
2490 [ # # ][ # # ]: 0 : NEWD( "PS", 1.359622E-03, CDC_Power ); // *** German Pferdestaerke
[ # # ]
2491 : :
2492 : : // MAGNETISM: 1 Tesla is...
2493 [ # # ][ # # ]: 0 : NEWDP( "T", 1.0000000000000000E00, CDC_Magnetism ); // Tesla
[ # # ]
2494 [ # # ][ # # ]: 0 : NEWDP( "ga", 1.0000000000000000E04, CDC_Magnetism ); // Gauss
[ # # ]
2495 : :
2496 : : // TEMERATURE: 1 Kelvin is...
2497 [ # # ][ # # ]: 0 : NEWL( "C", 1.0000000000000000E00, -2.7315000000000000E02, CDC_Temperature ); // Celsius
[ # # ]
2498 [ # # ][ # # ]: 0 : NEWL( "cel", 1.0000000000000000E00, -2.7315000000000000E02, CDC_Temperature ); // Celsius also
[ # # ]
2499 [ # # ][ # # ]: 0 : NEWL( "F", 1.8000000000000000E00, -2.5537222222222222E02, CDC_Temperature ); // Fahrenheit
[ # # ]
2500 [ # # ][ # # ]: 0 : NEWL( "fah", 1.8000000000000000E00, -2.5537222222222222E02, CDC_Temperature ); // Fahrenheit also
[ # # ]
2501 [ # # ][ # # ]: 0 : NEWLP( "K", 1.0000000000000000E00, +0.0000000000000000E00, CDC_Temperature ); // Kelvin
[ # # ]
2502 [ # # ][ # # ]: 0 : NEWLP( "kel", 1.0000000000000000E00, +0.0000000000000000E00, CDC_Temperature ); // Kelvin also
[ # # ]
2503 [ # # ][ # # ]: 0 : NEWL( "Reau", 8.0000000000000000E-01, -2.7315000000000000E02, CDC_Temperature ); // *** Reaumur
[ # # ]
2504 [ # # ][ # # ]: 0 : NEWL( "Rank", 1.8000000000000000E00, +0.0000000000000000E00, CDC_Temperature ); // *** Rankine
[ # # ]
2505 : :
2506 : : // VOLUMNE: 1 Liter is...
2507 [ # # ][ # # ]: 0 : NEWD( "tsp", 2.0288413621105798E02, CDC_Volume ); // US teaspoon 1/768 gallon
[ # # ]
2508 [ # # ][ # # ]: 0 : NEWD( "tbs", 6.7628045403685994E01, CDC_Volume ); // US tablespoon 1/256 gallon
[ # # ]
2509 [ # # ][ # # ]: 0 : NEWD( "oz", 3.3814022701842997E01, CDC_Volume ); // Ounce Liquid 1/128 gallon
[ # # ]
2510 [ # # ][ # # ]: 0 : NEWD( "cup", 4.2267528377303746E00, CDC_Volume ); // Cup 1/16 gallon
[ # # ]
2511 [ # # ][ # # ]: 0 : NEWD( "pt", 2.1133764188651873E00, CDC_Volume ); // US Pint 1/8 gallon
[ # # ]
2512 [ # # ][ # # ]: 0 : NEWD( "us_pt", 2.1133764188651873E00, CDC_Volume ); // US Pint also
[ # # ]
2513 [ # # ][ # # ]: 0 : NEWD( "uk_pt", 1.7597539863927023E00, CDC_Volume ); // UK Pint 1/8 imperial gallon
[ # # ]
2514 [ # # ][ # # ]: 0 : NEWD( "qt", 1.0566882094325937E00, CDC_Volume ); // Quart 1/4 gallon
[ # # ]
2515 [ # # ][ # # ]: 0 : NEWD( "gal", 2.6417205235814842E-01, CDC_Volume ); // Gallon 1/3.785411784
[ # # ]
2516 [ # # ][ # # ]: 0 : NEWDP( "l", 1.0000000000000000E00, CDC_Volume ); // Liter
[ # # ]
2517 [ # # ][ # # ]: 0 : NEWDP( "L", 1.0000000000000000E00, CDC_Volume ); // Liter also
[ # # ]
2518 [ # # ][ # # ]: 0 : NEWDP( "lt", 1.0000000000000000E00, CDC_Volume ); // Liter also
[ # # ]
2519 [ # # ][ # # ]: 0 : NEWDP( "m3", 1.0000000000000000E-03, CDC_Volume ); // *** Cubic Meter
[ # # ]
2520 [ # # ][ # # ]: 0 : NEWD( "mi3", 2.3991275857892772E-13, CDC_Volume ); // *** Cubic Britsh Mile
[ # # ]
2521 [ # # ][ # # ]: 0 : NEWD( "Nmi3", 1.5742621468581148E-13, CDC_Volume ); // *** Cubic Nautical Mile
[ # # ]
2522 [ # # ][ # # ]: 0 : NEWD( "in3", 6.1023744094732284E01, CDC_Volume ); // *** Cubic Inch
[ # # ]
2523 [ # # ][ # # ]: 0 : NEWD( "ft3", 3.5314666721488590E-02, CDC_Volume ); // *** Cubic Foot
[ # # ]
2524 [ # # ][ # # ]: 0 : NEWD( "yd3", 1.3079506193143922E-03, CDC_Volume ); // *** Cubic Yard
[ # # ]
2525 [ # # ][ # # ]: 0 : NEWDP( "ang3", 1.0000000000000000E27, CDC_Volume ); // *** Cubic Angstroem
[ # # ]
2526 [ # # ][ # # ]: 0 : NEWD( "Pica3", 2.2776990435870636E07, CDC_Volume ); // *** Cubic Pica
[ # # ]
2527 [ # # ][ # # ]: 0 : NEWD( "barrel", 6.2898107704321051E-03, CDC_Volume ); // *** Barrel (=42gal)
[ # # ]
2528 [ # # ][ # # ]: 0 : NEWD( "bushel", 2.837759E-02, CDC_Volume ); // *** Bushel
[ # # ]
2529 [ # # ][ # # ]: 0 : NEWD( "regton", 3.531467E-04, CDC_Volume ); // *** Register ton
[ # # ]
2530 [ # # ][ # # ]: 0 : NEWD( "GRT", 3.531467E-04, CDC_Volume ); // *** Register ton also
[ # # ]
2531 [ # # ][ # # ]: 0 : NEWD( "Schooner", 2.3529411764705882E00, CDC_Volume ); // *** austr. Schooner
[ # # ]
2532 [ # # ][ # # ]: 0 : NEWD( "Middy", 3.5087719298245614E00, CDC_Volume ); // *** austr. Middy
[ # # ]
2533 [ # # ][ # # ]: 0 : NEWD( "Glass", 5.0000000000000000E00, CDC_Volume ); // *** austr. Glass
[ # # ]
2534 [ # # ][ # # ]: 0 : NEWD( "Sixpack", 0.5, CDC_Volume ); // ***
[ # # ]
2535 [ # # ][ # # ]: 0 : NEWD( "Humpen", 2.0, CDC_Volume ); // ***
[ # # ]
2536 [ # # ][ # # ]: 0 : NEWD( "ly3", 1.1810108125623799E-51, CDC_Volume ); // *** Cubic light-year
[ # # ]
2537 [ # # ][ # # ]: 0 : NEWD( "MTON", 1.4125866688595436E00, CDC_Volume ); // *** Measurement ton
[ # # ]
2538 [ # # ][ # # ]: 0 : NEWD( "tspm", 5.0000000000000000E02, CDC_Volume ); // *** Modern teaspoon
[ # # ]
2539 [ # # ][ # # ]: 0 : NEWD( "uk_gal", 2.1996924829908779E-01, CDC_Volume ); // U.K. / Imperial gallon 1/4.54609
[ # # ]
2540 [ # # ][ # # ]: 0 : NEWD( "uk_qt", 8.7987699319635115E-01, CDC_Volume ); // U.K. / Imperial quart 1/4 imperial gallon
[ # # ]
2541 : :
2542 : : // 1 Square Meter is...
2543 [ # # ][ # # ]: 0 : NEWDP( "m2", 1.0000000000000000E00, CDC_Area ); // *** Square Meter
[ # # ]
2544 [ # # ][ # # ]: 0 : NEWD( "mi2", 3.8610215854244585E-07, CDC_Area ); // *** Square Britsh Mile
[ # # ]
2545 [ # # ][ # # ]: 0 : NEWD( "Nmi2", 2.9155334959812286E-07, CDC_Area ); // *** Square Nautical Mile
[ # # ]
2546 [ # # ][ # # ]: 0 : NEWD( "in2", 1.5500031000062000E03, CDC_Area ); // *** Square Inch
[ # # ]
2547 [ # # ][ # # ]: 0 : NEWD( "ft2", 1.0763910416709722E01, CDC_Area ); // *** Square Foot
[ # # ]
2548 [ # # ][ # # ]: 0 : NEWD( "yd2", 1.1959900463010803E00, CDC_Area ); // *** Square Yard
[ # # ]
2549 [ # # ][ # # ]: 0 : NEWDP( "ang2", 1.0000000000000000E20, CDC_Area ); // *** Square Angstroem
[ # # ]
2550 [ # # ][ # # ]: 0 : NEWD( "Pica2", 8.0352160704321409E06, CDC_Area ); // *** Square Pica
[ # # ]
2551 [ # # ][ # # ]: 0 : NEWD( "Morgen", 4.0000000000000000E-04, CDC_Area ); // *** Morgen
[ # # ]
2552 [ # # ][ # # ]: 0 : NEWDP( "ar", 1.000000E-02, CDC_Area ); // *** Ar
[ # # ]
2553 [ # # ][ # # ]: 0 : NEWD( "acre", 2.471053815E-04, CDC_Area ); // *** Acre
[ # # ]
2554 [ # # ][ # # ]: 0 : NEWD( "uk_acre", 2.4710538146716534E-04, CDC_Area ); // *** International acre
[ # # ]
2555 [ # # ][ # # ]: 0 : NEWD( "us_acre", 2.4710439304662790E-04, CDC_Area ); // *** U.S. survey/statute acre
[ # # ]
2556 [ # # ][ # # ]: 0 : NEWD( "ly2", 1.1172985860549147E-32, CDC_Area ); // *** Square Light-year
[ # # ]
2557 [ # # ][ # # ]: 0 : NEWD( "ha", 1.000000E-04, CDC_Area ); // *** Hectare
[ # # ]
2558 [ # # ][ # # ]: 0 : NEWD( "Quadratlatschen",5.6689342403628117914,CDC_Area ); // ***
[ # # ]
2559 : :
2560 : : // SPEED: 1 Meter per Second is...
2561 [ # # ][ # # ]: 0 : NEWDP( "m/s", 1.0000000000000000E00, CDC_Speed ); // *** Meters per Second
[ # # ]
2562 [ # # ][ # # ]: 0 : NEWDP( "m/sec", 1.0000000000000000E00, CDC_Speed ); // *** Meters per Second also
[ # # ]
2563 [ # # ][ # # ]: 0 : NEWDP( "m/h", 3.6000000000000000E03, CDC_Speed ); // *** Meters per Hour
[ # # ]
2564 [ # # ][ # # ]: 0 : NEWDP( "m/hr", 3.6000000000000000E03, CDC_Speed ); // *** Meters per Hour also
[ # # ]
2565 [ # # ][ # # ]: 0 : NEWD( "mph", 2.2369362920544023E00, CDC_Speed ); // *** Britsh Miles per Hour
[ # # ]
2566 [ # # ][ # # ]: 0 : NEWD( "kn", 1.9438444924406048E00, CDC_Speed ); // *** Knot = Nautical Miles per Hour
[ # # ]
2567 [ # # ][ # # ]: 0 : NEWD( "admkn", 1.9438446603753486E00, CDC_Speed ); // *** Admiralty Knot
[ # # ]
2568 [ # # ][ # # ]: 0 : NEWD( "wahnsinnige Geschwindigkeit", 2.0494886343432328E-14, CDC_Speed ); // ***
[ # # ]
2569 [ # # ][ # # ]: 0 : NEWD( "ludicrous speed", 2.0494886343432328E-14, CDC_Speed ); // ***
[ # # ]
2570 [ # # ][ # # ]: 0 : NEWD( "laecherliche Geschwindigkeit", 4.0156958471424288E-06, CDC_Speed); // ***
[ # # ]
2571 [ # # ][ # # ]: 0 : NEWD( "ridiculous speed", 4.0156958471424288E-06, CDC_Speed); // ***
[ # # ]
2572 : :
2573 : : // INFORMATION: 1 Bit is...
2574 [ # # ][ # # ]: 0 : NEWDP( "bit", 1.00E00, CDC_Information); // *** Bit
[ # # ]
2575 [ # # ][ # # ]: 0 : NEWDP( "byte", 1.25E-01, CDC_Information); // *** Byte
[ # # ]
2576 : 0 : }
2577 : :
2578 : :
2579 : 0 : ConvertDataList::~ConvertDataList()
2580 : : {
2581 [ # # ]: 0 : for( ConvertData* p = First() ; p ; p = Next() )
2582 [ # # ][ # # ]: 0 : delete p;
2583 [ # # ]: 0 : }
2584 : :
2585 : :
2586 : 0 : double ConvertDataList::Convert( double fVal, const STRING& rFrom, const STRING& rTo ) THROWDEF_RTE_IAE
2587 : : {
2588 : 0 : ConvertData* pFrom = NULL;
2589 : 0 : ConvertData* pTo = NULL;
2590 : 0 : sal_Bool bSearchFrom = sal_True;
2591 : 0 : sal_Bool bSearchTo = sal_True;
2592 : 0 : sal_Int16 nLevelFrom = 0;
2593 : 0 : sal_Int16 nLevelTo = 0;
2594 : :
2595 : 0 : ConvertData* p = First();
2596 [ # # ][ # # ]: 0 : while( p && ( bSearchFrom || bSearchTo ) )
[ # # ][ # # ]
2597 : : {
2598 [ # # ]: 0 : if( bSearchFrom )
2599 : : {
2600 : 0 : sal_Int16 n = p->GetMatchingLevel( rFrom );
2601 [ # # ]: 0 : if( n != INV_MATCHLEV )
2602 : : {
2603 [ # # ]: 0 : if( n )
2604 : : { // only first match for partial equality rulz a little bit more
2605 : 0 : pFrom = p;
2606 : 0 : nLevelFrom = n;
2607 : : }
2608 : : else
2609 : : { // ... but exact match rulz most
2610 : 0 : pFrom = p;
2611 : 0 : bSearchFrom = sal_False;
2612 : 0 : nLevelFrom = n;
2613 : : }
2614 : : }
2615 : : }
2616 : :
2617 [ # # ]: 0 : if( bSearchTo )
2618 : : {
2619 : 0 : sal_Int16 n = p->GetMatchingLevel( rTo );
2620 [ # # ]: 0 : if( n != INV_MATCHLEV )
2621 : : {
2622 [ # # ]: 0 : if( n )
2623 : : { // only first match for partial equality rulz a little bit more
2624 : 0 : pTo = p;
2625 : 0 : nLevelTo = n;
2626 : : }
2627 : : else
2628 : : { // ... but exact match rulz most
2629 : 0 : pTo = p;
2630 : 0 : bSearchTo = sal_False;
2631 : 0 : nLevelTo = n;
2632 : : }
2633 : : }
2634 : : }
2635 : :
2636 : 0 : p = Next();
2637 : : }
2638 : :
2639 [ # # ][ # # ]: 0 : if( pFrom && pTo )
2640 : 0 : return pFrom->Convert( fVal, *pTo, nLevelFrom, nLevelTo );
2641 : : else
2642 [ # # ]: 0 : THROW_IAE;
2643 : : }
2644 : :
2645 : :
2646 : :
2647 : : //-----------------------------------------------------------------------------
2648 : :
2649 : 0 : ScaDate::ScaDate() :
2650 : : nOrigDay( 1 ),
2651 : : nDay( 1 ),
2652 : : nMonth( 1 ),
2653 : : nYear( 1900 ),
2654 : : bLastDayMode( sal_True ),
2655 : : bLastDay( sal_False ),
2656 : : b30Days( sal_False ),
2657 : 0 : bUSMode( sal_False )
2658 : : {
2659 : 0 : }
2660 : :
2661 : 0 : ScaDate::ScaDate( sal_Int32 nNullDate, sal_Int32 nDate, sal_Int32 nBase )
2662 : : {
2663 : 0 : DaysToDate( nNullDate + nDate, nOrigDay, nMonth, nYear );
2664 : 0 : bLastDayMode = (nBase != 5);
2665 : 0 : bLastDay = (nOrigDay >= ::DaysInMonth( nMonth, nYear ));
2666 [ # # ][ # # ]: 0 : b30Days = (nBase == 0) || (nBase == 4);
2667 : 0 : bUSMode = (nBase == 0);
2668 : 0 : setDay();
2669 : 0 : }
2670 : :
2671 : 0 : ScaDate::ScaDate( const ScaDate& rCopy ) :
2672 : : nOrigDay( rCopy.nOrigDay ),
2673 : : nDay( rCopy.nDay ),
2674 : : nMonth( rCopy.nMonth ),
2675 : : nYear( rCopy.nYear ),
2676 : : bLastDayMode( rCopy.bLastDayMode ),
2677 : : bLastDay( rCopy.bLastDay ),
2678 : : b30Days( rCopy.b30Days ),
2679 : 0 : bUSMode( rCopy.bUSMode )
2680 : : {
2681 : 0 : }
2682 : :
2683 : 0 : ScaDate& ScaDate::operator=( const ScaDate& rCopy )
2684 : : {
2685 [ # # ]: 0 : if( this != &rCopy )
2686 : : {
2687 : 0 : nOrigDay = rCopy.nOrigDay;
2688 : 0 : nDay = rCopy.nDay;
2689 : 0 : nMonth = rCopy.nMonth;
2690 : 0 : nYear = rCopy.nYear;
2691 : 0 : bLastDayMode = rCopy.bLastDayMode;
2692 : 0 : bLastDay = rCopy.bLastDay;
2693 : 0 : b30Days = rCopy.b30Days;
2694 : 0 : bUSMode = rCopy.bUSMode;
2695 : : }
2696 : 0 : return *this;
2697 : : }
2698 : :
2699 : 0 : void ScaDate::setDay()
2700 : : {
2701 [ # # ]: 0 : if( b30Days )
2702 : : {
2703 : : // 30-days-mode: set nDay to 30 if original was last day in month
2704 : 0 : nDay = Min( nOrigDay, static_cast< sal_uInt16 >( 30 ) );
2705 [ # # ][ # # ]: 0 : if( bLastDay || (nDay >= ::DaysInMonth( nMonth, nYear )) )
[ # # ]
2706 : 0 : nDay = 30;
2707 : : }
2708 : : else
2709 : : {
2710 : : // set nDay to last day in this month if original was last day
2711 : 0 : sal_uInt16 nLastDay = ::DaysInMonth( nMonth, nYear );
2712 [ # # ]: 0 : nDay = bLastDay ? nLastDay : Min( nOrigDay, nLastDay );
2713 : : }
2714 : 0 : }
2715 : :
2716 : 0 : sal_Int32 ScaDate::getDaysInMonthRange( sal_uInt16 nFrom, sal_uInt16 nTo ) const
2717 : : {
2718 [ # # ]: 0 : if( nFrom > nTo )
2719 : 0 : return 0;
2720 : :
2721 : 0 : sal_Int32 nRet = 0;
2722 [ # # ]: 0 : if( b30Days )
2723 : 0 : nRet = (nTo - nFrom + 1) * 30;
2724 : : else
2725 : : {
2726 [ # # ]: 0 : for( sal_uInt16 nMonthIx = nFrom; nMonthIx <= nTo; ++nMonthIx )
2727 : 0 : nRet += getDaysInMonth( nMonthIx );
2728 : : }
2729 : 0 : return nRet;
2730 : : }
2731 : :
2732 : 0 : sal_Int32 ScaDate::getDaysInYearRange( sal_uInt16 nFrom, sal_uInt16 nTo ) const
2733 : : {
2734 [ # # ]: 0 : if( nFrom > nTo )
2735 : 0 : return 0;
2736 : :
2737 [ # # ]: 0 : return b30Days ? ((nTo - nFrom + 1) * 360) : ::GetDaysInYears( nFrom, nTo );
2738 : : }
2739 : :
2740 : 0 : void ScaDate::doAddYears( sal_Int32 nYearCount ) throw( lang::IllegalArgumentException )
2741 : : {
2742 : 0 : sal_Int32 nNewYear = nYearCount + nYear;
2743 [ # # ][ # # ]: 0 : if( (nNewYear < 0) || (nNewYear > 0x7FFF) )
2744 [ # # ]: 0 : throw lang::IllegalArgumentException();
2745 : 0 : nYear = static_cast< sal_uInt16 >( nNewYear );
2746 : 0 : }
2747 : :
2748 : 0 : void ScaDate::addMonths( sal_Int32 nMonthCount ) throw( lang::IllegalArgumentException )
2749 : : {
2750 : 0 : sal_Int32 nNewMonth = nMonthCount + nMonth;
2751 [ # # ]: 0 : if( nNewMonth > 12 )
2752 : : {
2753 : 0 : --nNewMonth;
2754 : 0 : doAddYears( nNewMonth / 12 );
2755 : 0 : nMonth = static_cast< sal_uInt16 >( nNewMonth % 12 ) + 1;
2756 : : }
2757 [ # # ]: 0 : else if( nNewMonth < 1 )
2758 : : {
2759 : 0 : doAddYears( nNewMonth / 12 - 1 );
2760 : 0 : nMonth = static_cast< sal_uInt16 >( nNewMonth % 12 + 12 );
2761 : : }
2762 : : else
2763 : 0 : nMonth = static_cast< sal_uInt16 >( nNewMonth );
2764 : 0 : setDay();
2765 : 0 : }
2766 : :
2767 : 0 : sal_Int32 ScaDate::getDate( sal_Int32 nNullDate ) const
2768 : : {
2769 : 0 : sal_uInt16 nLastDay = ::DaysInMonth( nMonth, nYear );
2770 [ # # ][ # # ]: 0 : sal_uInt16 nRealDay = (bLastDayMode && bLastDay) ? nLastDay : Min( nLastDay, nOrigDay );
2771 : 0 : return ::DateToDays( nRealDay, nMonth, nYear ) - nNullDate;
2772 : : }
2773 : :
2774 : 0 : sal_Int32 ScaDate::getDiff( const ScaDate& rFrom, const ScaDate& rTo ) throw( lang::IllegalArgumentException )
2775 : : {
2776 [ # # ][ # # ]: 0 : if( rFrom > rTo )
2777 [ # # ]: 0 : return getDiff( rTo, rFrom );
2778 : :
2779 : 0 : sal_Int32 nDiff = 0;
2780 : 0 : ScaDate aFrom( rFrom );
2781 : 0 : ScaDate aTo( rTo );
2782 : :
2783 [ # # ]: 0 : if( rTo.b30Days )
2784 : : {
2785 : : // corrections for base 0 (US NASD)
2786 [ # # ]: 0 : if( rTo.bUSMode )
2787 : : {
2788 [ # # ][ # # ]: 0 : if( ((rFrom.nMonth == 2) || (rFrom.nDay < 30)) && (aTo.nOrigDay == 31) )
[ # # ]
2789 : 0 : aTo.nDay = 31;
2790 [ # # ][ # # ]: 0 : else if( (aTo.nMonth == 2) && aTo.bLastDay )
2791 : 0 : aTo.nDay = ::DaysInMonth( 2, aTo.nYear );
2792 : : }
2793 : : // corrections for base 4 (Europe)
2794 : : else
2795 : : {
2796 [ # # ][ # # ]: 0 : if( (aFrom.nMonth == 2) && (aFrom.nDay == 30) )
2797 : 0 : aFrom.nDay = ::DaysInMonth( 2, aFrom.nYear );
2798 [ # # ][ # # ]: 0 : if( (aTo.nMonth == 2) && (aTo.nDay == 30) )
2799 : 0 : aTo.nDay = ::DaysInMonth( 2, aTo.nYear );
2800 : : }
2801 : : }
2802 : :
2803 [ # # ][ # # ]: 0 : if( (aFrom.nYear < aTo.nYear) || ((aFrom.nYear == aTo.nYear) && (aFrom.nMonth < aTo.nMonth)) )
[ # # ]
2804 : : {
2805 : : // move aFrom to 1st day of next month
2806 [ # # ]: 0 : nDiff = aFrom.getDaysInMonth() - aFrom.nDay + 1;
2807 : 0 : aFrom.nOrigDay = aFrom.nDay = 1;
2808 : 0 : aFrom.bLastDay = sal_False;
2809 [ # # ]: 0 : aFrom.addMonths( 1 );
2810 : :
2811 [ # # ]: 0 : if( aFrom.nYear < aTo.nYear )
2812 : : {
2813 : : // move aFrom to 1st day of next year
2814 [ # # ]: 0 : nDiff += aFrom.getDaysInMonthRange( aFrom.nMonth, 12 );
2815 [ # # ]: 0 : aFrom.addMonths( 13 - aFrom.nMonth );
2816 : :
2817 : : // move aFrom to 1st day of this year
2818 : 0 : nDiff += aFrom.getDaysInYearRange( aFrom.nYear, aTo.nYear - 1 );
2819 [ # # ]: 0 : aFrom.addYears( aTo.nYear - aFrom.nYear );
2820 : : }
2821 : :
2822 : : // move aFrom to 1st day of this month
2823 [ # # ]: 0 : nDiff += aFrom.getDaysInMonthRange( aFrom.nMonth, aTo.nMonth - 1 );
2824 [ # # ]: 0 : aFrom.addMonths( aTo.nMonth - aFrom.nMonth );
2825 : : }
2826 : : // finally add remaining days in this month
2827 : 0 : nDiff += aTo.nDay - aFrom.nDay;
2828 : 0 : return nDiff > 0 ? nDiff : 0;
2829 : : }
2830 : :
2831 : 0 : sal_Bool ScaDate::operator<( const ScaDate& rCmp ) const
2832 : : {
2833 [ # # ]: 0 : if( nYear != rCmp.nYear )
2834 : 0 : return nYear < rCmp.nYear;
2835 [ # # ]: 0 : if( nMonth != rCmp.nMonth )
2836 : 0 : return nMonth < rCmp.nMonth;
2837 [ # # ]: 0 : if( nDay != rCmp.nDay )
2838 : 0 : return nDay < rCmp.nDay;
2839 [ # # ][ # # ]: 0 : if( bLastDay || rCmp.bLastDay )
2840 [ # # ][ # # ]: 0 : return !bLastDay && rCmp.bLastDay;
2841 : 0 : return nOrigDay < rCmp.nOrigDay;
2842 : : }
2843 : :
2844 : :
2845 : :
2846 : : //-----------------------------------------------------------------------------
2847 : :
2848 : 17 : ScaAnyConverter::ScaAnyConverter( const uno::Reference< lang::XMultiServiceFactory >& xServiceFact ) :
2849 : 17 : bHasValidFormat( sal_False )
2850 : : {
2851 [ + - ]: 17 : if( xServiceFact.is() )
2852 : : {
2853 [ + - ]: 17 : uno::Reference< uno::XInterface > xInstance = xServiceFact->createInstance(
2854 [ + - ][ + - ]: 17 : OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.util.NumberFormatter" )) );
2855 [ + - ][ + - ]: 17 : xFormatter = uno::Reference< util::XNumberFormatter >( xInstance, uno::UNO_QUERY );
2856 : : }
2857 : 17 : }
2858 : :
2859 : 7 : ScaAnyConverter::~ScaAnyConverter()
2860 : : {
2861 : 7 : }
2862 : :
2863 : 0 : void ScaAnyConverter::init( const uno::Reference< beans::XPropertySet >& xPropSet ) throw( uno::RuntimeException )
2864 : : {
2865 : : // try to get default number format
2866 : 0 : bHasValidFormat = sal_False;
2867 [ # # ]: 0 : if( xFormatter.is() )
2868 : : {
2869 : : // get XFormatsSupplier from outer XPropertySet
2870 [ # # ]: 0 : uno::Reference< util::XNumberFormatsSupplier > xFormatsSupp( xPropSet, uno::UNO_QUERY );
2871 [ # # ]: 0 : if( xFormatsSupp.is() )
2872 : : {
2873 : : // get XNumberFormatTypes from XNumberFormatsSupplier to get standard index
2874 [ # # ][ # # ]: 0 : uno::Reference< util::XNumberFormats > xFormats( xFormatsSupp->getNumberFormats() );
2875 [ # # ]: 0 : uno::Reference< util::XNumberFormatTypes > xFormatTypes( xFormats, uno::UNO_QUERY );
2876 [ # # ]: 0 : if( xFormatTypes.is() )
2877 : : {
2878 : 0 : lang::Locale eLocale;
2879 [ # # ][ # # ]: 0 : nDefaultFormat = xFormatTypes->getStandardIndex( eLocale );
2880 [ # # ][ # # ]: 0 : xFormatter->attachNumberFormatsSupplier( xFormatsSupp );
2881 : 0 : bHasValidFormat = sal_True;
2882 : 0 : }
2883 : 0 : }
2884 : : }
2885 : 0 : }
2886 : :
2887 : 0 : double ScaAnyConverter::convertToDouble( const OUString& rString ) const throw( lang::IllegalArgumentException )
2888 : : {
2889 : 0 : double fValue = 0.0;
2890 [ # # ]: 0 : if( bHasValidFormat )
2891 : : {
2892 : : try
2893 : : {
2894 [ # # ][ # # ]: 0 : fValue = xFormatter->convertStringToNumber( nDefaultFormat, rString );
2895 : : }
2896 [ # # ]: 0 : catch( uno::Exception& )
2897 : : {
2898 [ # # ]: 0 : throw lang::IllegalArgumentException();
2899 : : }
2900 : : }
2901 : : else
2902 : : {
2903 : : rtl_math_ConversionStatus eStatus;
2904 : : sal_Int32 nEnd;
2905 : 0 : fValue = ::rtl::math::stringToDouble( rString, '.', ',', &eStatus, &nEnd );
2906 [ # # ][ # # ]: 0 : if( (eStatus != rtl_math_ConversionStatus_Ok) || (nEnd < rString.getLength()) )
[ # # ]
2907 [ # # ]: 0 : throw lang::IllegalArgumentException();
2908 : : }
2909 : 0 : return fValue;
2910 : : }
2911 : :
2912 : 0 : sal_Bool ScaAnyConverter::getDouble(
2913 : : double& rfResult,
2914 : : const uno::Any& rAny ) const throw( lang::IllegalArgumentException )
2915 : : {
2916 : 0 : rfResult = 0.0;
2917 : 0 : sal_Bool bContainsVal = sal_True;
2918 [ # # # # ]: 0 : switch( rAny.getValueTypeClass() )
2919 : : {
2920 : : case uno::TypeClass_VOID:
2921 : 0 : bContainsVal = sal_False;
2922 : 0 : break;
2923 : : case uno::TypeClass_DOUBLE:
2924 : 0 : rAny >>= rfResult;
2925 : 0 : break;
2926 : : case uno::TypeClass_STRING:
2927 : : {
2928 : 0 : const OUString* pString = static_cast< const OUString* >( rAny.getValue() );
2929 [ # # ]: 0 : if( !pString->isEmpty() )
2930 : 0 : rfResult = convertToDouble( *pString );
2931 : : else
2932 : 0 : bContainsVal = sal_False;
2933 : : }
2934 : 0 : break;
2935 : : default:
2936 [ # # ]: 0 : throw lang::IllegalArgumentException();
2937 : : }
2938 : 0 : return bContainsVal;
2939 : : }
2940 : :
2941 : 0 : sal_Bool ScaAnyConverter::getDouble(
2942 : : double& rfResult,
2943 : : const uno::Reference< beans::XPropertySet >& xPropSet,
2944 : : const uno::Any& rAny ) throw( uno::RuntimeException, lang::IllegalArgumentException )
2945 : : {
2946 : 0 : init( xPropSet );
2947 : 0 : return getDouble( rfResult, rAny );
2948 : : }
2949 : :
2950 : 0 : double ScaAnyConverter::getDouble(
2951 : : const uno::Reference< beans::XPropertySet >& xPropSet,
2952 : : const uno::Any& rAny,
2953 : : double fDefault ) throw( uno::RuntimeException, lang::IllegalArgumentException )
2954 : : {
2955 : : double fResult;
2956 [ # # ][ # # ]: 0 : if( !getDouble( fResult, xPropSet, rAny ) )
2957 : 0 : fResult = fDefault;
2958 : 0 : return fResult;
2959 : : }
2960 : :
2961 : 0 : sal_Bool ScaAnyConverter::getInt32(
2962 : : sal_Int32& rnResult,
2963 : : const uno::Reference< beans::XPropertySet >& xPropSet,
2964 : : const uno::Any& rAny ) throw( uno::RuntimeException, lang::IllegalArgumentException )
2965 : : {
2966 : : double fResult;
2967 [ # # ]: 0 : sal_Bool bContainsVal = getDouble( fResult, xPropSet, rAny );
2968 [ # # ][ # # ]: 0 : if( (fResult <= -2147483649.0) || (fResult >= 2147483648.0) )
2969 [ # # ]: 0 : throw lang::IllegalArgumentException();
2970 : :
2971 : 0 : rnResult = static_cast< sal_Int32 >( fResult );
2972 : 0 : return bContainsVal;
2973 : : }
2974 : :
2975 : 0 : sal_Int32 ScaAnyConverter::getInt32(
2976 : : const uno::Reference< beans::XPropertySet >& xPropSet,
2977 : : const uno::Any& rAny,
2978 : : sal_Int32 nDefault ) throw( uno::RuntimeException, lang::IllegalArgumentException )
2979 : : {
2980 : : sal_Int32 nResult;
2981 [ # # ][ # # ]: 0 : if( !getInt32( nResult, xPropSet, rAny ) )
2982 : 0 : nResult = nDefault;
2983 : 0 : return nResult;
2984 : : }
2985 : :
2986 : :
2987 : :
2988 : : //-----------------------------------------------------------------------------
2989 : :
2990 : :
2991 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|