Path: blob/main_old/src/tests/compiler_tests/ConstantFoldingNaN_test.cpp
1693 views
//1// Copyright 2016 The ANGLE Project Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//5// ConstantFoldingNaN_test.cpp:6// Tests for constant folding that results in NaN according to IEEE and should also generate a7// warning. The ESSL spec does not mandate generating NaNs, but this is reasonable behavior in8// this case.9//1011#include "tests/test_utils/ConstantFoldingTest.h"1213using namespace sh;1415namespace16{1718class ConstantFoldingNaNExpressionTest : public ConstantFoldingExpressionTest19{20public:21ConstantFoldingNaNExpressionTest() {}2223void evaluateFloatNaN(const std::string &floatString)24{25evaluateFloat(floatString);26ASSERT_TRUE(constantFoundInAST(std::numeric_limits<float>::quiet_NaN()));27ASSERT_TRUE(hasWarning());28}29};3031} // anonymous namespace3233// Test that infinity - infinity evaluates to NaN.34TEST_F(ConstantFoldingNaNExpressionTest, FoldInfinityMinusInfinity)35{36const std::string &floatString = "1.0e2048 - 1.0e2048";37evaluateFloatNaN(floatString);38}3940// Test that infinity + negative infinity evaluates to NaN.41TEST_F(ConstantFoldingNaNExpressionTest, FoldInfinityPlusNegativeInfinity)42{43const std::string &floatString = "1.0e2048 + (-1.0e2048)";44evaluateFloatNaN(floatString);45}4647// Test that infinity multiplied by zero evaluates to NaN.48TEST_F(ConstantFoldingNaNExpressionTest, FoldInfinityMultipliedByZero)49{50const std::string &floatString = "1.0e2048 * 0.0";51evaluateFloatNaN(floatString);52}5354// Test that infinity divided by infinity evaluates to NaN.55TEST_F(ConstantFoldingNaNExpressionTest, FoldInfinityDividedByInfinity)56{57const std::string &floatString = "1.0e2048 / 1.0e2048";58evaluateFloatNaN(floatString);59}6061// Test that zero divided by zero evaluates to NaN.62TEST_F(ConstantFoldingNaNExpressionTest, FoldZeroDividedByZero)63{64const std::string &floatString = "0.0 / 0.0";65evaluateFloatNaN(floatString);66}676869