1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
24 #define PREC_long_double 3
27 bool is_equal(T x
, T y
, sal_Int16 _nPrec
)
29 // due to the fact that this check looks only if both values are equal
30 // we only need to look on one value
32 // 14 digits will announce the checkPrecisionSize
43 case PREC_long_double
:
59 if (_nPrec
!= PREC_long_double
)
61 printf("double equal: %.20f\n", x
);
62 printf(" %.20f\n", y
);
64 //here nPrecOfN is the number after dot
65 sal_Int32 nBeforeDot
= sal_Int32( log10(x
) );
70 //printf("nPRECISION is %d\n", nPRECISION);
71 sal_Int32 nPrecOfN
= -nPRECISION
+ nBeforeDot
;
73 if (_nPrec
!= PREC_long_double
)
74 printf("nPrecOfN is %" SAL_PRIdINT32
"\n", nPrecOfN
);
76 double nPrec
= pow(0.1, -nPrecOfN
);
78 if (_nPrec
!= PREC_long_double
)
79 printf(" prec: %.20f\n", nPrec
);
81 double nDelta
= fabs( x
- y
) ;
83 if (_nPrec
!= PREC_long_double
)
85 printf(" delta: %.20f\n", nDelta
);
86 printf(" nPrec: %.20f\n", nPrec
);
87 printf("delta must be less or equal to prec\n\n");
92 // values are not equal
100 bool is_float_equal(float x
, float y
)
102 return is_equal
<float>(x
, y
, PREC_float
);
104 bool is_double_equal(double x
, double y
)
106 return is_equal
<double>(x
, y
, PREC_double
);
109 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */