update dev300-m57
[ooovba.git] / sal / qa / rtl / math / test_rtl_math.cxx
blob0fbb19702adcd545d6661ff8a3763af52f4ae77b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: test_rtl_math.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sal.hxx"
34 #include "rtl/math.h"
35 #include "rtl/math.hxx"
36 #include "rtl/strbuf.hxx"
37 #include "rtl/string.h"
38 #include "rtl/string.hxx"
39 #include "rtl/textenc.h"
40 // #include "rtl/tres.h"
41 #include <testshl/tresstatewrapper.hxx>
42 #include "rtl/ustring.hxx"
43 #include "sal/types.h"
45 #include <stdlib.h>
47 namespace {
49 struct FloatTraits
51 typedef float Number;
53 static inline char const * getPrefix() { return "float"; }
56 struct DoubleTraits
58 typedef double Number;
60 static inline char const * getPrefix() { return "double"; }
63 struct StringTraits
65 typedef rtl::OString String;
67 static inline char const * getPrefix() { return "OString"; }
69 static inline rtl::OString createFromAscii(char const * pString)
70 { return rtl::OString(pString); }
72 static inline void appendBuffer(rtl::OStringBuffer & rBuffer,
73 rtl::OString const & rString)
74 { rBuffer.append(rString); }
76 static inline rtl::OString doubleToString(double fValue,
77 rtl_math_StringFormat eFormat,
78 sal_Int32 nDecPlaces,
79 sal_Char cDecSeparator,
80 bool bEraseTrailingDecZeros)
82 return rtl::math::doubleToString(fValue, eFormat, nDecPlaces,
83 cDecSeparator, bEraseTrailingDecZeros);
87 struct UStringTraits
89 typedef rtl::OUString String;
91 static inline char const * getPrefix() { return "OUString"; }
93 static inline rtl::OUString createFromAscii(char const * pString)
94 { return rtl::OUString::createFromAscii(pString); }
96 static inline void appendBuffer(rtl::OStringBuffer & rBuffer,
97 rtl::OUString const & rString)
98 { rBuffer.append(rtl::OUStringToOString(rString, RTL_TEXTENCODING_UTF8)); }
100 static inline rtl::OUString doubleToString(double fValue,
101 rtl_math_StringFormat eFormat,
102 sal_Int32 nDecPlaces,
103 sal_Unicode cDecSeparator,
104 bool bEraseTrailingDecZeros)
106 return rtl::math::doubleToUString(fValue, eFormat, nDecPlaces,
107 cDecSeparator,
108 bEraseTrailingDecZeros);
112 struct TestNumberToString
114 double fValue;
115 rtl_math_StringFormat eFormat;
116 sal_Int32 nDecPlaces;
117 char cDecSeparator;
118 bool bEraseTrailingDecZeros;
119 char const * pResult;
122 template< typename StringT, typename NumberT >
123 bool testNumberToString(hTestResult pTestResult,
124 TestNumberToString const & rTest)
126 typename NumberT::Number fValue = static_cast< typename NumberT::Number >(rTest.fValue);
127 if (fValue != rTest.fValue)
128 return true;
130 // LLA: t_print("size: %d ", sizeof(fValue));
131 typename StringT::String aResult1;
133 aResult1 = StringT::doubleToString(fValue, rTest.eFormat, rTest.nDecPlaces,
134 rTest.cDecSeparator,
135 rTest.bEraseTrailingDecZeros);
137 typename StringT::String aResult2(StringT::createFromAscii(rTest.pResult));
139 // LLA: rtl::OStringBuffer aBuf;
140 // LLA: StringT::appendBuffer(aBuf, aResult1);
141 // LLA: t_print("aResult1: %s ", aBuf.getStr());
142 // LLA:
143 // LLA: rtl::OStringBuffer aBuf2;
144 // LLA: StringT::appendBuffer(aBuf2, aResult2);
145 // LLA: t_print("aResult2: %s\n", aBuf2.getStr());
147 bool bSuccess = aResult1 == aResult2;
149 rtl::OStringBuffer aBuffer;
150 aBuffer.append(StringT::getPrefix());
151 aBuffer.append(RTL_CONSTASCII_STRINGPARAM("/"));
152 aBuffer.append(NumberT::getPrefix());
153 aBuffer.append(RTL_CONSTASCII_STRINGPARAM(" doubleToString("));
154 aBuffer.append(fValue);
155 aBuffer.append(RTL_CONSTASCII_STRINGPARAM(", "));
156 aBuffer.append(static_cast< sal_Int32 >(rTest.eFormat));
157 aBuffer.append(RTL_CONSTASCII_STRINGPARAM(", "));
158 aBuffer.append(rTest.nDecPlaces);
159 aBuffer.append(RTL_CONSTASCII_STRINGPARAM(", "));
160 aBuffer.append(rTest.cDecSeparator);
161 aBuffer.append(RTL_CONSTASCII_STRINGPARAM(", "));
162 aBuffer.append(static_cast< sal_Int32 >(rTest.bEraseTrailingDecZeros));
163 aBuffer.append(RTL_CONSTASCII_STRINGPARAM("): "));
164 StringT::appendBuffer(aBuffer, aResult1);
165 if (!bSuccess)
167 aBuffer.append(RTL_CONSTASCII_STRINGPARAM(" != "));
168 StringT::appendBuffer(aBuffer, aResult2);
170 // call to the real test checker
171 // pTestResult->pFuncs->state_(pTestResult, bSuccess, "test_rtl_math",
172 // aBuffer.getStr(), false);
173 c_rtl_tres_state(pTestResult, bSuccess, aBuffer.getStr(), "testNumberToString");
174 return bSuccess;
177 template< typename StringT, typename NumberT >
178 bool testNumberToString(hTestResult pTestResult,
179 TestNumberToString const * pTests, size_t nCount)
181 bool bSuccess = true;
182 for (size_t i = 0; i < nCount; ++i)
183 bSuccess &= testNumberToString< StringT, NumberT >(pTestResult,
184 pTests[i]);
185 return bSuccess;
188 struct TestStringToNumberToString
190 char const * pValue;
191 rtl_math_StringFormat eFormat;
192 sal_Int32 nDecPlaces;
193 char cDecSeparator;
194 bool bEraseTrailingDecZeros;
195 char const * pResult;
198 template< typename StringT >
199 bool testStringToNumberToString(hTestResult pTestResult,
200 TestStringToNumberToString const & rTest)
202 double d = rtl::math::stringToDouble(StringT::createFromAscii(rTest.pValue),
203 rTest.cDecSeparator, 0, 0, 0);
204 typename StringT::String aResult1(
205 StringT::doubleToString(d, rTest.eFormat, rTest.nDecPlaces,
206 rTest.cDecSeparator,
207 rTest.bEraseTrailingDecZeros));
208 typename StringT::String aResult2(StringT::createFromAscii(rTest.pResult));
209 bool bSuccess = aResult1 == aResult2;
210 rtl::OStringBuffer aBuffer;
211 aBuffer.append(StringT::getPrefix());
212 aBuffer.append(RTL_CONSTASCII_STRINGPARAM(
213 " doubleToString(stringToDouble("));
214 aBuffer.append(rTest.pValue);
215 aBuffer.append(RTL_CONSTASCII_STRINGPARAM(", "));
216 aBuffer.append(rTest.cDecSeparator);
217 aBuffer.append(RTL_CONSTASCII_STRINGPARAM("), "));
218 aBuffer.append(static_cast< sal_Int32 >(rTest.eFormat));
219 aBuffer.append(RTL_CONSTASCII_STRINGPARAM(", "));
220 aBuffer.append(rTest.nDecPlaces);
221 aBuffer.append(RTL_CONSTASCII_STRINGPARAM(", "));
222 aBuffer.append(rTest.cDecSeparator);
223 aBuffer.append(RTL_CONSTASCII_STRINGPARAM(", "));
224 aBuffer.append(static_cast< sal_Int32 >(rTest.bEraseTrailingDecZeros));
225 aBuffer.append(RTL_CONSTASCII_STRINGPARAM("): "));
226 StringT::appendBuffer(aBuffer, aResult1);
227 if (!bSuccess)
229 aBuffer.append(RTL_CONSTASCII_STRINGPARAM(" != "));
230 StringT::appendBuffer(aBuffer, aResult2);
232 // call to the real test checker
233 // pTestResult->pFuncs->state_(pTestResult, bSuccess, "test_rtl_math",
234 // aBuffer.getStr(), false);
235 c_rtl_tres_state(pTestResult, bSuccess, aBuffer.getStr(), "testStringToNumberToString");
237 return bSuccess;
240 template< typename StringT >
241 bool testStringToNumberToString(hTestResult pTestResult,
242 TestStringToNumberToString const * pTests,
243 size_t nCount)
245 bool bSuccess = true;
246 for (size_t i = 0; i < nCount; ++i)
247 bSuccess &= testStringToNumberToString< StringT >(pTestResult,
248 pTests[i]);
249 return bSuccess;
254 extern "C" sal_Bool SAL_CALL test_rtl_math(hTestResult pTestResult)
256 bool bReturn = true;
259 static TestNumberToString const aTest[]
260 = { // 1, 1+2^-1, ..., 1+2^-52
261 // Too few decimal digits are printed, so that various different
262 // double values lead to the same output:
263 { 1, rtl_math_StringFormat_Automatic,
264 rtl_math_DecimalPlaces_Max, '.', true, "1" },
265 { 1.5, rtl_math_StringFormat_Automatic,
266 rtl_math_DecimalPlaces_Max, '.', true, "1.5" },
267 { 1.25, rtl_math_StringFormat_Automatic,
268 rtl_math_DecimalPlaces_Max, '.', true, "1.25" },
269 { 1.125, rtl_math_StringFormat_Automatic,
270 rtl_math_DecimalPlaces_Max, '.', true, "1.125" },
271 { 1.0625, rtl_math_StringFormat_Automatic,
272 rtl_math_DecimalPlaces_Max, '.', true, "1.0625" },
273 { 1.03125, rtl_math_StringFormat_Automatic,
274 rtl_math_DecimalPlaces_Max, '.', true, "1.03125" },
275 { 1.015625, rtl_math_StringFormat_Automatic,
276 rtl_math_DecimalPlaces_Max, '.', true, "1.015625" },
277 { 1.0078125, rtl_math_StringFormat_Automatic,
278 rtl_math_DecimalPlaces_Max, '.', true, "1.0078125" },
279 { 1.00390625, rtl_math_StringFormat_Automatic,
280 rtl_math_DecimalPlaces_Max, '.', true, "1.00390625" },
281 { 1.001953125, rtl_math_StringFormat_Automatic,
282 rtl_math_DecimalPlaces_Max, '.', true, "1.001953125" },
283 { 1.0009765625, rtl_math_StringFormat_Automatic,
284 rtl_math_DecimalPlaces_Max, '.', true, "1.0009765625" },
285 { 1.00048828125, rtl_math_StringFormat_Automatic,
286 rtl_math_DecimalPlaces_Max, '.', true, "1.00048828125" },
287 { 1.000244140625, rtl_math_StringFormat_Automatic,
288 rtl_math_DecimalPlaces_Max, '.', true, "1.000244140625" },
289 { 1.0001220703125, rtl_math_StringFormat_Automatic,
290 rtl_math_DecimalPlaces_Max, '.', true, "1.0001220703125" },
291 { 1.00006103515625, rtl_math_StringFormat_Automatic,
292 rtl_math_DecimalPlaces_Max, '.', true, "1.00006103515625" },
293 { 1.000030517578125, rtl_math_StringFormat_Automatic,
294 rtl_math_DecimalPlaces_Max, '.', true, "1.00003051757813" },
295 { 1.0000152587890625, rtl_math_StringFormat_Automatic,
296 rtl_math_DecimalPlaces_Max, '.', true, "1.00001525878906" },
297 { 1.00000762939453125, rtl_math_StringFormat_Automatic,
298 rtl_math_DecimalPlaces_Max, '.', true, "1.00000762939453" },
299 { 1.000003814697265625, rtl_math_StringFormat_Automatic,
300 rtl_math_DecimalPlaces_Max, '.', true, "1.00000381469727" },
301 { 1.0000019073486328125, rtl_math_StringFormat_Automatic,
302 rtl_math_DecimalPlaces_Max, '.', true, "1.00000190734863" },
303 { 1.00000095367431640625, rtl_math_StringFormat_Automatic,
304 rtl_math_DecimalPlaces_Max, '.', true, "1.00000095367432" },
305 { 1.000000476837158203125, rtl_math_StringFormat_Automatic,
306 rtl_math_DecimalPlaces_Max, '.', true, "1.00000047683716" },
307 { 1.0000002384185791015625, rtl_math_StringFormat_Automatic,
308 rtl_math_DecimalPlaces_Max, '.', true, "1.00000023841858" },
309 { 1.00000011920928955078125, rtl_math_StringFormat_Automatic,
310 rtl_math_DecimalPlaces_Max, '.', true, "1.00000011920929" },
311 { 1.000000059604644775390625, rtl_math_StringFormat_Automatic,
312 rtl_math_DecimalPlaces_Max, '.', true, "1.00000005960464" },
313 { 1.0000000298023223876953125, rtl_math_StringFormat_Automatic,
314 rtl_math_DecimalPlaces_Max, '.', true, "1.00000002980232" },
315 { 1.00000001490116119384765625, rtl_math_StringFormat_Automatic,
316 rtl_math_DecimalPlaces_Max, '.', true, "1.00000001490116" },
317 { 1.000000007450580596923828125,
318 rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
319 '.', true, "1.00000000745058" },
320 { 1.0000000037252902984619140625,
321 rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
322 '.', true, "1.00000000372529" },
323 { 1.00000000186264514923095703125,
324 rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
325 '.', true, "1.00000000186265" },
326 { 1.000000000931322574615478515625,
327 rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
328 '.', true, "1.00000000093132" },
329 { 1.0000000004656612873077392578125,
330 rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
331 '.', true, "1.00000000046566" },
332 { 1.00000000023283064365386962890625,
333 rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
334 '.', true, "1.00000000023283" },
335 { 1.000000000116415321826934814453125,
336 rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
337 '.', true, "1.00000000011642" },
338 { 1.0000000000582076609134674072265625,
339 rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
340 '.', true, "1.00000000005821" },
341 { 1.00000000002910383045673370361328125,
342 rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
343 '.', true, "1.0000000000291" },
344 { 1.000000000014551915228366851806640625,
345 rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
346 '.', true, "1.00000000001455" },
347 { 1.0000000000072759576141834259033203125,
348 rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
349 '.', true, "1.00000000000728" },
350 { 1.00000000000363797880709171295166015625,
351 rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
352 '.', true, "1.00000000000364" },
353 { 1.000000000001818989403545856475830078125,
354 rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
355 '.', true, "1.00000000000182" },
356 { 1.0000000000009094947017729282379150390625,
357 rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
358 '.', true, "1.00000000000091" },
359 { 1.00000000000045474735088646411895751953125,
360 rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
361 '.', true, "1.00000000000045" },
362 { 1.000000000000227373675443232059478759765625,
363 rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
364 '.', true, "1.00000000000023" },
365 { 1.0000000000001136868377216160297393798828125,
366 rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
367 '.', true, "1.00000000000011" },
368 { 1.00000000000005684341886080801486968994140625,
369 rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
370 '.', true, "1.00000000000006" },
371 { 1.000000000000028421709430404007434844970703125,
372 rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
373 '.', true, "1.00000000000003" },
374 { 1.0000000000000142108547152020037174224853515625,
375 rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
376 '.', true, "1.00000000000001" },
377 { 1.00000000000000710542735760100185871124267578125,
378 rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
379 '.', true, "1.00000000000001" },
380 { 1.000000000000003552713678800500929355621337890625,
381 rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
382 '.', true, "1" },
383 { 1.0000000000000017763568394002504646778106689453125,
384 rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
385 '.', true, "1" },
386 { 1.00000000000000088817841970012523233890533447265625,
387 rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
388 '.', true, "1" },
389 { 1.000000000000000444089209850062616169452667236328125,
390 rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
391 '.', true, "1" },
392 { 1.0000000000000002220446049250313080847263336181640625,
393 rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
394 '.', true, "1" },
396 // 1, 1+2^-1, ..., 1+2^-52
397 // Too few decimal digits are printed, so that various different
398 // double values lead to the same output:
399 { 1, rtl_math_StringFormat_F, 53, '.', false,
400 "1.00000000000000000000000000000000000000000000000000000" },
401 { 1.5, rtl_math_StringFormat_F, 53, '.', false,
402 "1.50000000000000000000000000000000000000000000000000000" },
403 { 1.25, rtl_math_StringFormat_F, 53, '.', false,
404 "1.25000000000000000000000000000000000000000000000000000" },
405 { 1.125, rtl_math_StringFormat_F, 53, '.', false,
406 "1.12500000000000000000000000000000000000000000000000000" },
407 { 1.0625, rtl_math_StringFormat_F, 53, '.', false,
408 "1.06250000000000000000000000000000000000000000000000000" },
409 { 1.03125, rtl_math_StringFormat_F, 53, '.', false,
410 "1.03125000000000000000000000000000000000000000000000000" },
411 { 1.015625, rtl_math_StringFormat_F, 53, '.', false,
412 "1.01562500000000000000000000000000000000000000000000000" },
413 { 1.0078125, rtl_math_StringFormat_F, 53, '.', false,
414 "1.00781250000000000000000000000000000000000000000000000" },
415 { 1.00390625, rtl_math_StringFormat_F, 53, '.', false,
416 "1.00390625000000000000000000000000000000000000000000000" },
417 { 1.001953125, rtl_math_StringFormat_F, 53, '.', false,
418 "1.00195312500000000000000000000000000000000000000000000" },
419 { 1.0009765625, rtl_math_StringFormat_F, 53, '.', false,
420 "1.00097656250000000000000000000000000000000000000000000" },
421 { 1.00048828125, rtl_math_StringFormat_F, 53, '.', false,
422 "1.00048828125000000000000000000000000000000000000000000" },
423 { 1.000244140625, rtl_math_StringFormat_F, 53, '.', false,
424 "1.00024414062500000000000000000000000000000000000000000" },
425 { 1.0001220703125, rtl_math_StringFormat_F, 53, '.', false,
426 "1.00012207031250000000000000000000000000000000000000000" },
427 { 1.00006103515625, rtl_math_StringFormat_F, 53, '.', false,
428 "1.00006103515625000000000000000000000000000000000000000" },
429 { 1.000030517578125, rtl_math_StringFormat_F, 53, '.', false,
430 "1.00003051757813000000000000000000000000000000000000000" },
431 { 1.0000152587890625, rtl_math_StringFormat_F, 53, '.', false,
432 "1.00001525878906000000000000000000000000000000000000000" },
433 { 1.00000762939453125, rtl_math_StringFormat_F, 53, '.', false,
434 "1.00000762939453000000000000000000000000000000000000000" },
435 { 1.000003814697265625, rtl_math_StringFormat_F, 53, '.', false,
436 "1.00000381469727000000000000000000000000000000000000000" },
437 { 1.0000019073486328125, rtl_math_StringFormat_F, 53, '.',
438 false,
439 "1.00000190734863000000000000000000000000000000000000000" },
440 { 1.00000095367431640625, rtl_math_StringFormat_F, 53, '.',
441 false,
442 "1.00000095367432000000000000000000000000000000000000000" },
443 { 1.000000476837158203125, rtl_math_StringFormat_F, 53, '.',
444 false,
445 "1.00000047683716000000000000000000000000000000000000000" },
446 { 1.0000002384185791015625, rtl_math_StringFormat_F, 53, '.',
447 false,
448 "1.00000023841858000000000000000000000000000000000000000" },
449 { 1.00000011920928955078125, rtl_math_StringFormat_F, 53, '.',
450 false,
451 "1.00000011920929000000000000000000000000000000000000000" },
452 { 1.000000059604644775390625, rtl_math_StringFormat_F, 53, '.',
453 false,
454 "1.00000005960464000000000000000000000000000000000000000" },
455 { 1.0000000298023223876953125, rtl_math_StringFormat_F, 53, '.',
456 false,
457 "1.00000002980232000000000000000000000000000000000000000" },
458 { 1.00000001490116119384765625, rtl_math_StringFormat_F, 53,
459 '.', false,
460 "1.00000001490116000000000000000000000000000000000000000" },
461 { 1.000000007450580596923828125, rtl_math_StringFormat_F, 53,
462 '.', false,
463 "1.00000000745058000000000000000000000000000000000000000" },
464 { 1.0000000037252902984619140625, rtl_math_StringFormat_F, 53,
465 '.', false,
466 "1.00000000372529000000000000000000000000000000000000000" },
467 { 1.00000000186264514923095703125, rtl_math_StringFormat_F, 53,
468 '.', false,
469 "1.00000000186265000000000000000000000000000000000000000" },
470 { 1.000000000931322574615478515625, rtl_math_StringFormat_F, 53,
471 '.', false,
472 "1.00000000093132000000000000000000000000000000000000000" },
473 { 1.0000000004656612873077392578125, rtl_math_StringFormat_F,
474 53, '.', false,
475 "1.00000000046566000000000000000000000000000000000000000" },
476 { 1.00000000023283064365386962890625, rtl_math_StringFormat_F,
477 53, '.', false,
478 "1.00000000023283000000000000000000000000000000000000000" },
479 { 1.000000000116415321826934814453125, rtl_math_StringFormat_F,
480 53, '.', false,
481 "1.00000000011642000000000000000000000000000000000000000" },
482 { 1.0000000000582076609134674072265625, rtl_math_StringFormat_F,
483 53, '.', false,
484 "1.00000000005821000000000000000000000000000000000000000" },
485 { 1.00000000002910383045673370361328125,
486 rtl_math_StringFormat_F, 53, '.', false,
487 "1.00000000002910000000000000000000000000000000000000000" },
488 { 1.000000000014551915228366851806640625,
489 rtl_math_StringFormat_F, 53, '.', false,
490 "1.00000000001455000000000000000000000000000000000000000" },
491 { 1.0000000000072759576141834259033203125,
492 rtl_math_StringFormat_F, 53, '.', false,
493 "1.00000000000728000000000000000000000000000000000000000" },
494 { 1.00000000000363797880709171295166015625,
495 rtl_math_StringFormat_F, 53, '.', false,
496 "1.00000000000364000000000000000000000000000000000000000" },
497 { 1.000000000001818989403545856475830078125,
498 rtl_math_StringFormat_F, 53, '.', false,
499 "1.00000000000182000000000000000000000000000000000000000" },
500 { 1.0000000000009094947017729282379150390625,
501 rtl_math_StringFormat_F, 53, '.', false,
502 "1.00000000000091000000000000000000000000000000000000000" },
503 { 1.00000000000045474735088646411895751953125,
504 rtl_math_StringFormat_F, 53, '.', false,
505 "1.00000000000045000000000000000000000000000000000000000" },
506 { 1.000000000000227373675443232059478759765625,
507 rtl_math_StringFormat_F, 53, '.', false,
508 "1.00000000000023000000000000000000000000000000000000000" },
509 { 1.0000000000001136868377216160297393798828125,
510 rtl_math_StringFormat_F, 53, '.', false,
511 "1.00000000000011000000000000000000000000000000000000000" },
512 { 1.00000000000005684341886080801486968994140625,
513 rtl_math_StringFormat_F, 53, '.', false,
514 "1.00000000000006000000000000000000000000000000000000000" },
515 { 1.000000000000028421709430404007434844970703125,
516 rtl_math_StringFormat_F, 53, '.', false,
517 "1.00000000000003000000000000000000000000000000000000000" },
518 { 1.0000000000000142108547152020037174224853515625,
519 rtl_math_StringFormat_F, 53, '.', false,
520 "1.00000000000001000000000000000000000000000000000000000" },
521 { 1.00000000000000710542735760100185871124267578125,
522 rtl_math_StringFormat_F, 53, '.', false,
523 "1.00000000000001000000000000000000000000000000000000000" },
524 { 1.000000000000003552713678800500929355621337890625,
525 rtl_math_StringFormat_F, 53, '.', false,
526 "1.00000000000000000000000000000000000000000000000000000" },
527 { 1.0000000000000017763568394002504646778106689453125,
528 rtl_math_StringFormat_F, 53, '.', false,
529 "1.00000000000000000000000000000000000000000000000000000" },
530 { 1.00000000000000088817841970012523233890533447265625,
531 rtl_math_StringFormat_F, 53, '.', false,
532 "1.00000000000000000000000000000000000000000000000000000" },
533 { 1.000000000000000444089209850062616169452667236328125,
534 rtl_math_StringFormat_F, 53, '.', false,
535 "1.00000000000000000000000000000000000000000000000000000" },
536 { 1.0000000000000002220446049250313080847263336181640625,
537 rtl_math_StringFormat_F, 53, '.', false,
538 "1.00000000000000000000000000000000000000000000000000000" } };
539 size_t const nCount = sizeof aTest / sizeof aTest[0];
541 //LLA: the float tests are wrong here, due to the fact that
542 // we calculate with too less digits after the point
544 // bReturn &= testNumberToString< StringTraits, FloatTraits >(
545 // pTestResult, aTest, nCount);
546 bReturn &= testNumberToString< StringTraits, DoubleTraits >(
547 pTestResult, aTest, nCount);
548 // bReturn &= testNumberToString< UStringTraits, FloatTraits >(
549 // pTestResult, aTest, nCount);
550 bReturn &= testNumberToString< UStringTraits, DoubleTraits >(
551 pTestResult, aTest, nCount);
555 static TestStringToNumberToString const aTest[]
556 = { { "1", rtl_math_StringFormat_Automatic,
557 rtl_math_DecimalPlaces_Max, '.', true, "1" },
558 { " 1", rtl_math_StringFormat_Automatic,
559 rtl_math_DecimalPlaces_Max, '.', true, "1" },
560 { " 1", rtl_math_StringFormat_Automatic,
561 rtl_math_DecimalPlaces_Max, '.', true, "1" },
562 { "\t1", rtl_math_StringFormat_Automatic,
563 rtl_math_DecimalPlaces_Max, '.', true, "1" },
564 { "\t 1", rtl_math_StringFormat_Automatic,
565 rtl_math_DecimalPlaces_Max, '.', true, "1" },
566 { " \t1", rtl_math_StringFormat_Automatic,
567 rtl_math_DecimalPlaces_Max, '.', true, "1" },
569 { "-1", rtl_math_StringFormat_Automatic,
570 rtl_math_DecimalPlaces_Max, '.', true, "-1" },
571 { " -1", rtl_math_StringFormat_Automatic,
572 rtl_math_DecimalPlaces_Max, '.', true, "-1" },
573 { " -1", rtl_math_StringFormat_Automatic,
574 rtl_math_DecimalPlaces_Max, '.', true, "-1" },
575 { "\t-1", rtl_math_StringFormat_Automatic,
576 rtl_math_DecimalPlaces_Max, '.', true, "-1" },
577 { "\t -1", rtl_math_StringFormat_Automatic,
578 rtl_math_DecimalPlaces_Max, '.', true, "-1" },
579 { " \t-1", rtl_math_StringFormat_Automatic,
580 rtl_math_DecimalPlaces_Max, '.', true, "-1" },
582 { "1.#INF", rtl_math_StringFormat_Automatic,
583 rtl_math_DecimalPlaces_Max, '.', false, "1.#INF" },
584 { " 1.#INF", rtl_math_StringFormat_Automatic,
585 rtl_math_DecimalPlaces_Max, '.', false, "1.#INF" },
586 { " 1.#INF", rtl_math_StringFormat_Automatic,
587 rtl_math_DecimalPlaces_Max, '.', false, "1.#INF" },
588 { "\t1.#INF", rtl_math_StringFormat_Automatic,
589 rtl_math_DecimalPlaces_Max, '.', false, "1.#INF" },
590 { "\t 1.#INF", rtl_math_StringFormat_Automatic,
591 rtl_math_DecimalPlaces_Max, '.', false, "1.#INF" },
592 { " \t1.#INF", rtl_math_StringFormat_Automatic,
593 rtl_math_DecimalPlaces_Max, '.', false, "1.#INF" },
595 { "-1.#INF", rtl_math_StringFormat_Automatic,
596 rtl_math_DecimalPlaces_Max, '.', false, "-1.#INF" },
597 { " -1.#INF", rtl_math_StringFormat_Automatic,
598 rtl_math_DecimalPlaces_Max, '.', false, "-1.#INF" },
599 { " -1.#INF", rtl_math_StringFormat_Automatic,
600 rtl_math_DecimalPlaces_Max, '.', false, "-1.#INF" },
601 { "\t-1.#INF", rtl_math_StringFormat_Automatic,
602 rtl_math_DecimalPlaces_Max, '.', false, "-1.#INF" },
603 { "\t -1.#INF", rtl_math_StringFormat_Automatic,
604 rtl_math_DecimalPlaces_Max, '.', false, "-1.#INF" },
605 { " \t-1.#INF", rtl_math_StringFormat_Automatic,
606 rtl_math_DecimalPlaces_Max, '.', false, "-1.#INF" },
608 { "1.#NAN", rtl_math_StringFormat_Automatic,
609 rtl_math_DecimalPlaces_Max, '.', false, "1.#NAN" },
610 { " 1.#NAN", rtl_math_StringFormat_Automatic,
611 rtl_math_DecimalPlaces_Max, '.', false, "1.#NAN" },
612 { " 1.#NAN", rtl_math_StringFormat_Automatic,
613 rtl_math_DecimalPlaces_Max, '.', false, "1.#NAN" },
614 { "\t1.#NAN", rtl_math_StringFormat_Automatic,
615 rtl_math_DecimalPlaces_Max, '.', false, "1.#NAN" },
616 { "\t 1.#NAN", rtl_math_StringFormat_Automatic,
617 rtl_math_DecimalPlaces_Max, '.', false, "1.#NAN" },
618 { " \t1.#NAN", rtl_math_StringFormat_Automatic,
619 rtl_math_DecimalPlaces_Max, '.', false, "1.#NAN" },
621 { "-1.#NAN", rtl_math_StringFormat_Automatic,
622 rtl_math_DecimalPlaces_Max, '.', false, "-1.#NAN" },
623 { " -1.#NAN", rtl_math_StringFormat_Automatic,
624 rtl_math_DecimalPlaces_Max, '.', false, "-1.#NAN" },
625 { " -1.#NAN", rtl_math_StringFormat_Automatic,
626 rtl_math_DecimalPlaces_Max, '.', false, "-1.#NAN" },
627 { "\t-1.#NAN", rtl_math_StringFormat_Automatic,
628 rtl_math_DecimalPlaces_Max, '.', false, "-1.#NAN" },
629 { "\t -1.#NAN", rtl_math_StringFormat_Automatic,
630 rtl_math_DecimalPlaces_Max, '.', false, "-1.#NAN" },
631 { " \t-1.#NAN", rtl_math_StringFormat_Automatic,
632 rtl_math_DecimalPlaces_Max, '.', false, "-1.#NAN" },
634 { "3.14E-2000", rtl_math_StringFormat_E, 4, '.', false,
635 "0.0000E+000" },
636 { "3.14E-200", rtl_math_StringFormat_E, 4, '.', false,
637 "3.1400E-200" },
638 { "3.14E-20", rtl_math_StringFormat_E, 4, '.', false,
639 "3.1400E-020" },
640 { "3.14E-2", rtl_math_StringFormat_E, 4, '.', false,
641 "3.1400E-002" },
642 { "3.14E2", rtl_math_StringFormat_E, 4, '.', false,
643 "3.1400E+002" },
644 { "3.14E20", rtl_math_StringFormat_E, 4, '.', false,
645 "3.1400E+020" },
646 { "3.14E200", rtl_math_StringFormat_E, 4, '.', false,
647 "3.1400E+200" },
648 { "3.14E2000", rtl_math_StringFormat_E, 4, '.', false,
649 "1.#INF" },
651 size_t const nCount = sizeof aTest / sizeof aTest[0];
652 bReturn &= testStringToNumberToString< StringTraits >(
653 pTestResult, aTest, nCount);
654 bReturn &= testStringToNumberToString< UStringTraits >(
655 pTestResult, aTest, nCount);
658 return bReturn;
661 // -----------------------------------------------------------------------------
662 extern "C" void /* sal_Bool */ SAL_CALL test_rtl_math2( hTestResult hRtlTestResult )
664 c_rtl_tres_state_start(hRtlTestResult, "rtl_math" );
666 test_rtl_math( hRtlTestResult );
668 c_rtl_tres_state_end(hRtlTestResult, "rtl_math" );
670 // -----------------------------------------------------------------------------
671 void RegisterAdditionalFunctions(FktRegFuncPtr _pFunc)
673 if (_pFunc)
675 (_pFunc)(&test_rtl_math2, "");