1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: float.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_testshl2.hxx"
36 #include <math.h> // fabs()
37 // #include <sal/types.h>
39 #define sal_Int16 short
44 * min()/max() macros that also do
45 * strict type-checking.. See the
46 * "unnecessary" pointer comparison.
49 const typeof(x) _x = (x); \
50 const typeof(y) _y = (y); \
51 (void) (&_x == &_y); \
55 const typeof(x) _x = (x); \
56 const typeof(y) _y = (y); \
57 (void) (&_x == &_y); \
60 //------------------------------------------------------------------------
61 // testing the method toDouble()
62 //------------------------------------------------------------------------
64 sal_Int16 SAL_CALL
test_rtl_OString_checkPrecisionSize()
66 sal_Int16 nSize
= sizeof(T
);
69 // (i + 1) is the current precision
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;
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)
101 // imho i +- 1 == j is a good value
110 printf("warning: presision differs more than 1");
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
[] )
130 int main( int argc
, char* argv
[] )
137 // The following sets variables for GNU EMACS