@@ -1322,6 +1322,53 @@ TEST_F(LLVMCodeBuilderTest, Sqrt)
13221322 addOpTest (nan, 0 );
13231323}
13241324
1325+ TEST_F (LLVMCodeBuilderTest, Sin)
1326+ {
1327+ std::string expected;
1328+
1329+ auto addOpTest = [this , &expected](Value v1, double expectedResult) {
1330+ createBuilder (true );
1331+
1332+ m_builder->addConstValue (v1);
1333+ m_builder->createSin ();
1334+ m_builder->addFunctionCall (" test_print_number" , Compiler::StaticType::Void, { Compiler::StaticType::Number });
1335+
1336+ m_builder->addConstValue (v1);
1337+ m_builder->addFunctionCall (" test_const_number" , Compiler::StaticType::Number, { Compiler::StaticType::Number });
1338+ m_builder->createSin ();
1339+ m_builder->addFunctionCall (" test_print_number" , Compiler::StaticType::Void, { Compiler::StaticType::Number });
1340+
1341+ std::stringstream stream;
1342+ stream << expectedResult;
1343+ std::string str = stream.str () + ' \n ' ;
1344+ std::string expected = str + str;
1345+
1346+ auto code = m_builder->finalize ();
1347+ auto ctx = code->createExecutionContext (&m_target);
1348+
1349+ testing::internal::CaptureStdout ();
1350+ code->run (ctx.get ());
1351+ const std::string quotes1 = v1.isString () ? " \" " : " " ;
1352+ ASSERT_THAT (testing::internal::GetCapturedStdout (), Eq (expected)) << quotes1 << v1.toString () << quotes1;
1353+ };
1354+
1355+ static const double inf = std::numeric_limits<double >::infinity ();
1356+ static const double nan = std::numeric_limits<double >::quiet_NaN ();
1357+
1358+ addOpTest (30.0 , 0.5 );
1359+ addOpTest (90.0 , 1.0 );
1360+ addOpTest (2.8e-9 , 0.0 );
1361+ addOpTest (2.9e-9 , 1e-10 );
1362+ addOpTest (570.0 , -0.5 );
1363+ addOpTest (-30.0 , -0.5 );
1364+ addOpTest (-90.0 , -1.0 );
1365+ addOpTest (0.0 , 0.0 );
1366+ addOpTest (-0.0 , 0.0 );
1367+ addOpTest (inf, -nan); // negative NaN shouldn't be a problem
1368+ addOpTest (-inf, -nan);
1369+ addOpTest (nan, 0 );
1370+ }
1371+
13251372TEST_F (LLVMCodeBuilderTest, Yield)
13261373{
13271374 auto build = [this ]() {
0 commit comments