@@ -1369,6 +1369,53 @@ TEST_F(LLVMCodeBuilderTest, Sin)
13691369 addOpTest (nan, 0 );
13701370}
13711371
1372+ TEST_F (LLVMCodeBuilderTest, Cos)
1373+ {
1374+ std::string expected;
1375+
1376+ auto addOpTest = [this , &expected](Value v1, double expectedResult) {
1377+ createBuilder (true );
1378+
1379+ m_builder->addConstValue (v1);
1380+ m_builder->createCos ();
1381+ m_builder->addFunctionCall (" test_print_number" , Compiler::StaticType::Void, { Compiler::StaticType::Number });
1382+
1383+ m_builder->addConstValue (v1);
1384+ m_builder->addFunctionCall (" test_const_number" , Compiler::StaticType::Number, { Compiler::StaticType::Number });
1385+ m_builder->createCos ();
1386+ m_builder->addFunctionCall (" test_print_number" , Compiler::StaticType::Void, { Compiler::StaticType::Number });
1387+
1388+ std::stringstream stream;
1389+ stream << expectedResult;
1390+ std::string str = stream.str () + ' \n ' ;
1391+ std::string expected = str + str;
1392+
1393+ auto code = m_builder->finalize ();
1394+ auto ctx = code->createExecutionContext (&m_target);
1395+
1396+ testing::internal::CaptureStdout ();
1397+ code->run (ctx.get ());
1398+ const std::string quotes1 = v1.isString () ? " \" " : " " ;
1399+ ASSERT_THAT (testing::internal::GetCapturedStdout (), Eq (expected)) << quotes1 << v1.toString () << quotes1;
1400+ };
1401+
1402+ static const double inf = std::numeric_limits<double >::infinity ();
1403+ static const double nan = std::numeric_limits<double >::quiet_NaN ();
1404+
1405+ addOpTest (60.0 , 0.5 );
1406+ addOpTest (90.0 , 0.0 );
1407+ addOpTest (600.0 , -0.5 );
1408+ addOpTest (89.9999999971352 , 1e-10 );
1409+ addOpTest (89.999999999 , 0.0 );
1410+ addOpTest (-60.0 , 0.5 );
1411+ addOpTest (-90.0 , 0.0 );
1412+ addOpTest (0.0 , 1.0 );
1413+ addOpTest (-0.0 , 1.0 );
1414+ addOpTest (inf, -nan); // negative NaN shouldn't be a problem
1415+ addOpTest (-inf, -nan);
1416+ addOpTest (nan, 1.0 );
1417+ }
1418+
13721419TEST_F (LLVMCodeBuilderTest, Yield)
13731420{
13741421 auto build = [this ]() {
0 commit comments