update dev300-m58
[ooovba.git] / testshl2 / workben / garbage_dump / float.cxx
blob0159b86b32abd980f74d4aefcaf865841bcc52e6
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: float.cxx,v $
10 * $Revision: 1.4 $
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 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_testshl2.hxx"
34 #include <stdio.h>
35 #include <double>
36 #include <math.h> // fabs()
37 // #include <sal/types.h>
39 #define sal_Int16 short
40 #define SAL_CALL
42 // LLA: from kernel.h
44 * min()/max() macros that also do
45 * strict type-checking.. See the
46 * "unnecessary" pointer comparison.
48 #define MIN(x,y) ({ \
49 const typeof(x) _x = (x); \
50 const typeof(y) _y = (y); \
51 (void) (&_x == &_y); \
52 _x < _y ? _x : _y; })
54 #define MAX(x,y) ({ \
55 const typeof(x) _x = (x); \
56 const typeof(y) _y = (y); \
57 (void) (&_x == &_y); \
58 _x > _y ? _x : _y; })
60 //------------------------------------------------------------------------
61 // testing the method toDouble()
62 //------------------------------------------------------------------------
63 template<class T>
64 sal_Int16 SAL_CALL test_rtl_OString_checkPrecisionSize()
66 sal_Int16 nSize = sizeof(T);
67 T nCalcValue = 1.0;
69 // (i + 1) is the current precision
70 sal_Int16 i = 0;
71 for (i=0;i<50;i++)
73 nCalcValue *= 10;
74 T nValue = nCalcValue + 0.1;
75 T dSub = nValue - nCalcValue;
76 // ----- 0.11 ---- 0.1 ---- 0.09 -----
77 if (0.11 > dSub && dSub < 0.09)
79 // due to the fact, that the value is break down we sub 1 from the precision value
80 // but to suppress this, we start at zero, precision is i+1 till here --i;
81 break;
85 sal_Int16 j= 0;
86 nCalcValue = 1.0;
87 for (j=0;j<50;j++)
89 nCalcValue /= 10;
90 T nValue = nCalcValue + 1.0;
91 T dSub = nValue - 1.0;
92 // ---- 0.02 ----- 0.01 ---- 0 --- -0.99 ---- -0.98 ----
93 T dSubAbsolut = fabs(dSub);
94 // ---- 0.02 ----- 0.01 ---- 0 (cut)
95 if ( dSub == 0)
96 break;
98 if (i != j)
100 // hmmm....
101 // imho i +- 1 == j is a good value
102 int n = i - j;
103 if (n < 0) n = -n;
104 if (n <= 1)
106 return MIN(i,j);
108 else
110 printf("warning: presision differs more than 1");
114 return i;
117 void SAL_CALL test_precision( )
119 sal_Int16 nPrecision;
120 nPrecision = test_rtl_OString_checkPrecisionSize<float>();
121 nPrecision = test_rtl_OString_checkPrecisionSize<double>();
122 nPrecision = test_rtl_OString_checkPrecisionSize<long double>();
123 nPrecision = test_rtl_OString_checkPrecisionSize<Double>();
126 // ----------------------------------- Main -----------------------------------
127 #if (defined UNX) || (defined OS2)
128 int main( int argc, char* argv[] )
129 #else
130 int main( int argc, char* argv[] )
131 #endif
133 test_precision();
134 return 0;
137 // The following sets variables for GNU EMACS
138 // Local Variables:
139 // tab-width:4
140 // End: