Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/angle
Path: blob/main_old/src/tests/compiler_tests/ConstantFoldingNaN_test.cpp
1693 views
1
//
2
// Copyright 2016 The ANGLE Project Authors. All rights reserved.
3
// Use of this source code is governed by a BSD-style license that can be
4
// found in the LICENSE file.
5
//
6
// ConstantFoldingNaN_test.cpp:
7
// Tests for constant folding that results in NaN according to IEEE and should also generate a
8
// warning. The ESSL spec does not mandate generating NaNs, but this is reasonable behavior in
9
// this case.
10
//
11
12
#include "tests/test_utils/ConstantFoldingTest.h"
13
14
using namespace sh;
15
16
namespace
17
{
18
19
class ConstantFoldingNaNExpressionTest : public ConstantFoldingExpressionTest
20
{
21
public:
22
ConstantFoldingNaNExpressionTest() {}
23
24
void evaluateFloatNaN(const std::string &floatString)
25
{
26
evaluateFloat(floatString);
27
ASSERT_TRUE(constantFoundInAST(std::numeric_limits<float>::quiet_NaN()));
28
ASSERT_TRUE(hasWarning());
29
}
30
};
31
32
} // anonymous namespace
33
34
// Test that infinity - infinity evaluates to NaN.
35
TEST_F(ConstantFoldingNaNExpressionTest, FoldInfinityMinusInfinity)
36
{
37
const std::string &floatString = "1.0e2048 - 1.0e2048";
38
evaluateFloatNaN(floatString);
39
}
40
41
// Test that infinity + negative infinity evaluates to NaN.
42
TEST_F(ConstantFoldingNaNExpressionTest, FoldInfinityPlusNegativeInfinity)
43
{
44
const std::string &floatString = "1.0e2048 + (-1.0e2048)";
45
evaluateFloatNaN(floatString);
46
}
47
48
// Test that infinity multiplied by zero evaluates to NaN.
49
TEST_F(ConstantFoldingNaNExpressionTest, FoldInfinityMultipliedByZero)
50
{
51
const std::string &floatString = "1.0e2048 * 0.0";
52
evaluateFloatNaN(floatString);
53
}
54
55
// Test that infinity divided by infinity evaluates to NaN.
56
TEST_F(ConstantFoldingNaNExpressionTest, FoldInfinityDividedByInfinity)
57
{
58
const std::string &floatString = "1.0e2048 / 1.0e2048";
59
evaluateFloatNaN(floatString);
60
}
61
62
// Test that zero divided by zero evaluates to NaN.
63
TEST_F(ConstantFoldingNaNExpressionTest, FoldZeroDividedByZero)
64
{
65
const std::string &floatString = "0.0 / 0.0";
66
evaluateFloatNaN(floatString);
67
}
68
69