4
// $Id: //poco/1.2/Foundation/testsuite/src/FPETest.cpp#1 $
6
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
9
// Permission is hereby granted, free of charge, to any person or organization
10
// obtaining a copy of the software and accompanying documentation covered by
11
// this license (the "Software") to use, reproduce, display, distribute,
12
// execute, and transmit the Software, and to prepare derivative works of the
13
// Software, and to permit third-parties to whom the Software is furnished to
14
// do so, all subject to the following:
16
// The copyright notices in the Software and this entire statement, including
17
// the above license grant, this restriction and the following disclaimer,
18
// must be included in all copies of the Software, in whole or in part, and
19
// all derivative works of the Software, unless such copies or derivative
20
// works are solely in the form of machine-executable object code generated by
21
// a source language processor.
23
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
26
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
27
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
28
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29
// DEALINGS IN THE SOFTWARE.
34
#include "CppUnit/TestCaller.h"
35
#include "CppUnit/TestSuite.h"
36
#include "Poco/FPEnvironment.h"
42
FPETest::FPETest(const std::string& name): CppUnit::TestCase(name)
52
void FPETest::testClassify()
60
assert (FPE::isNaN(nan));
61
assert (!FPE::isNaN(a));
62
assert (FPE::isInfinite(inf));
63
assert (!FPE::isInfinite(a));
71
assert (FPE::isNaN(nan));
72
assert (!FPE::isNaN(a));
73
assert (FPE::isInfinite(inf));
74
assert (!FPE::isInfinite(a));
81
#elif defined(_MSC_VER)
82
#pragma optimize("", off)
86
double mult(double a, double b)
92
double div(double a, double b)
98
void FPETest::testFlags()
102
// some compilers are intelligent enough to optimize the calculations below away.
103
// unfortunately this leads to a failing test, so we have to trick out the
104
// compiler's optimizer a little bit by doing something with the results.
107
double c = div(a, b);
109
assert (FPE::isFlag(FPE::FP_DIVIDE_BY_ZERO));
110
assert (FPE::isInfinite(c));
116
assert (FPE::isFlag(FPE::FP_OVERFLOW));
117
assertEqualDelta(c, c, 0);
123
assert (FPE::isFlag(FPE::FP_UNDERFLOW));
124
assertEqualDelta(c, c, 0);
128
#if defined(__HP_aCC)
130
#elif defined(_MSC_VER)
131
#pragma optimize("", on)
135
void FPETest::testRound()
137
#if !defined(__osf__) && !defined(__VMS)
138
FPE::setRoundingMode(FPE::FP_ROUND_TONEAREST);
139
assert (FPE::getRoundingMode() == FPE::FP_ROUND_TONEAREST);
141
FPE env(FPE::FP_ROUND_TOWARDZERO);
142
assert (FPE::getRoundingMode() == FPE::FP_ROUND_TOWARDZERO);
144
assert (FPE::getRoundingMode() == FPE::FP_ROUND_TONEAREST);
149
void FPETest::setUp()
154
void FPETest::tearDown()
159
CppUnit::Test* FPETest::suite()
161
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("FPETest");
163
CppUnit_addTest(pSuite, FPETest, testClassify);
164
CppUnit_addTest(pSuite, FPETest, testFlags);
165
CppUnit_addTest(pSuite, FPETest, testRound);