@@ -1178,6 +1178,56 @@ TEST_F(LLVMCodeBuilderTest, Abs)
11781178 addOpTest (nan, 0 );
11791179}
11801180
1181+ TEST_F (LLVMCodeBuilderTest, Floor)
1182+ {
1183+ std::string expected;
1184+
1185+ auto addOpTest = [this , &expected](Value v1, double expectedResult) {
1186+ createBuilder (true );
1187+
1188+ m_builder->addConstValue (v1);
1189+ m_builder->createFloor ();
1190+ m_builder->addFunctionCall (" test_print_number" , Compiler::StaticType::Void, { Compiler::StaticType::Number });
1191+
1192+ m_builder->addConstValue (v1);
1193+ m_builder->addFunctionCall (" test_const_number" , Compiler::StaticType::Number, { Compiler::StaticType::Number });
1194+ m_builder->createFloor ();
1195+ m_builder->addFunctionCall (" test_print_number" , Compiler::StaticType::Void, { Compiler::StaticType::Number });
1196+
1197+ std::stringstream stream;
1198+ stream << expectedResult;
1199+ std::string str = stream.str () + ' \n ' ;
1200+ std::string expected = str + str;
1201+
1202+ auto code = m_builder->finalize ();
1203+ auto ctx = code->createExecutionContext (&m_target);
1204+
1205+ testing::internal::CaptureStdout ();
1206+ code->run (ctx.get ());
1207+ const std::string quotes1 = v1.isString () ? " \" " : " " ;
1208+ ASSERT_THAT (testing::internal::GetCapturedStdout (), Eq (expected)) << quotes1 << v1.toString () << quotes1;
1209+ };
1210+
1211+ static const double inf = std::numeric_limits<double >::infinity ();
1212+ static const double nan = std::numeric_limits<double >::quiet_NaN ();
1213+
1214+ addOpTest (4.0 , 4.0 );
1215+ addOpTest (3.2 , 3.0 );
1216+ addOpTest (3.5 , 3.0 );
1217+ addOpTest (3.6 , 3.0 );
1218+ addOpTest (0.0 , 0.0 );
1219+ addOpTest (-0.0 , -0.0 );
1220+ addOpTest (-2.4 , -3.0 );
1221+ addOpTest (-2.5 , -3.0 );
1222+ addOpTest (-2.6 , -3.0 );
1223+ addOpTest (-0.4 , -1.0 );
1224+ addOpTest (-0.5 , -1.0 );
1225+ addOpTest (-0.51 , -1.0 );
1226+ addOpTest (inf, inf);
1227+ addOpTest (-inf, -inf);
1228+ addOpTest (nan, 0 );
1229+ }
1230+
11811231TEST_F (LLVMCodeBuilderTest, Yield)
11821232{
11831233 auto build = [this ]() {
0 commit comments