@@ -75,3 +75,151 @@ TEST(InterpreterTest, MulI32) {
75
75
76
76
EXPECT_EQ (results, expected);
77
77
}
78
+
79
+ TEST (InterpreterTest, AddF32) {
80
+ Module wasm;
81
+ IRBuilder builder (wasm);
82
+
83
+ ASSERT_FALSE (builder.makeConst (Literal (float (0.0 ))).getErr ());
84
+ ASSERT_FALSE (builder.makeConst (Literal (float (1.0 ))).getErr ());
85
+ ASSERT_FALSE (builder.makeBinary (AddFloat32).getErr ());
86
+
87
+ auto expr = builder.build ();
88
+ ASSERT_FALSE (expr.getErr ());
89
+
90
+ auto results = Interpreter{}.run (*expr);
91
+ std::vector<Literal> expected{Literal (float (1.0 ))};
92
+
93
+ EXPECT_EQ (results, expected);
94
+ }
95
+
96
+ TEST (InterpreterTest, SubF32) {
97
+ Module wasm;
98
+ IRBuilder builder (wasm);
99
+
100
+ ASSERT_FALSE (builder.makeConst (Literal (float (1.0 ))).getErr ());
101
+ ASSERT_FALSE (builder.makeConst (Literal (float (2.0 ))).getErr ());
102
+ ASSERT_FALSE (builder.makeBinary (SubFloat32).getErr ());
103
+
104
+ auto expr = builder.build ();
105
+ ASSERT_FALSE (expr.getErr ());
106
+
107
+ auto results = Interpreter{}.run (*expr);
108
+ std::vector<Literal> expected{Literal (float (-1.0 ))};
109
+
110
+ EXPECT_EQ (results, expected);
111
+ }
112
+
113
+ TEST (InterpreterTest, MulF32) {
114
+ Module wasm;
115
+ IRBuilder builder (wasm);
116
+
117
+ ASSERT_FALSE (builder.makeConst (Literal (float (1.5 ))).getErr ());
118
+ ASSERT_FALSE (builder.makeConst (Literal (float (2.0 ))).getErr ());
119
+ ASSERT_FALSE (builder.makeBinary (MulFloat32).getErr ());
120
+
121
+ auto expr = builder.build ();
122
+ ASSERT_FALSE (expr.getErr ());
123
+
124
+ auto results = Interpreter{}.run (*expr);
125
+ std::vector<Literal> expected{Literal (float (3.0 ))};
126
+
127
+ EXPECT_EQ (results, expected);
128
+ }
129
+
130
+ TEST (InterpreterTest, DivF32) {
131
+ Module wasm;
132
+ IRBuilder builder (wasm);
133
+
134
+ ASSERT_FALSE (builder.makeConst (Literal (float (5.0 ))).getErr ());
135
+ ASSERT_FALSE (builder.makeConst (Literal (float (2.0 ))).getErr ());
136
+ ASSERT_FALSE (builder.makeBinary (DivFloat32).getErr ());
137
+
138
+ auto expr = builder.build ();
139
+ ASSERT_FALSE (expr.getErr ());
140
+
141
+ auto results = Interpreter{}.run (*expr);
142
+ std::vector<Literal> expected{Literal (float (2.5 ))};
143
+
144
+ EXPECT_EQ (results, expected);
145
+ }
146
+
147
+ TEST (InterpreterTest, SqrtF32) {
148
+ Module wasm;
149
+ IRBuilder builder (wasm);
150
+
151
+ ASSERT_FALSE (builder.makeConst (Literal (float (5.0 ))).getErr ());
152
+ ASSERT_FALSE (builder.makeUnary (SqrtFloat32).getErr ());
153
+
154
+ auto expr = builder.build ();
155
+ ASSERT_FALSE (expr.getErr ());
156
+
157
+ auto results = Interpreter{}.run (*expr);
158
+ std::vector<Literal> expected{Literal (float (2.2360679775 ))};
159
+
160
+ EXPECT_EQ (results, expected);
161
+ }
162
+
163
+ TEST (InterpreterTest, CeilF32) {
164
+ Module wasm;
165
+ IRBuilder builder (wasm);
166
+
167
+ ASSERT_FALSE (builder.makeConst (Literal (float (1.5 ))).getErr ());
168
+ ASSERT_FALSE (builder.makeUnary (CeilFloat32).getErr ());
169
+
170
+ auto expr = builder.build ();
171
+ ASSERT_FALSE (expr.getErr ());
172
+
173
+ auto results = Interpreter{}.run (*expr);
174
+ std::vector<Literal> expected{Literal (float (2.0 ))};
175
+
176
+ EXPECT_EQ (results, expected);
177
+ }
178
+
179
+ TEST (InterpreterTest, FloorF32) {
180
+ Module wasm;
181
+ IRBuilder builder (wasm);
182
+
183
+ ASSERT_FALSE (builder.makeConst (Literal (float (1.5 ))).getErr ());
184
+ ASSERT_FALSE (builder.makeUnary (FloorFloat32).getErr ());
185
+
186
+ auto expr = builder.build ();
187
+ ASSERT_FALSE (expr.getErr ());
188
+
189
+ auto results = Interpreter{}.run (*expr);
190
+ std::vector<Literal> expected{Literal (float (1.0 ))};
191
+
192
+ EXPECT_EQ (results, expected);
193
+ }
194
+
195
+ TEST (InterpreterTest, TruncF32) {
196
+ Module wasm;
197
+ IRBuilder builder (wasm);
198
+
199
+ ASSERT_FALSE (builder.makeConst (Literal (float (2.017281 ))).getErr ());
200
+ ASSERT_FALSE (builder.makeUnary (TruncFloat32).getErr ());
201
+
202
+ auto expr = builder.build ();
203
+ ASSERT_FALSE (expr.getErr ());
204
+
205
+ auto results = Interpreter{}.run (*expr);
206
+ std::vector<Literal> expected{Literal (float (2.0 ))};
207
+
208
+ EXPECT_EQ (results, expected);
209
+ }
210
+
211
+ TEST (InterpreterTest, NearF32) {
212
+ Module wasm;
213
+ IRBuilder builder (wasm);
214
+
215
+ ASSERT_FALSE (builder.makeConst (Literal (float (2.5 ))).getErr ());
216
+ ASSERT_FALSE (builder.makeUnary (NearestFloat32).getErr ());
217
+
218
+ auto expr = builder.build ();
219
+ ASSERT_FALSE (expr.getErr ());
220
+
221
+ auto results = Interpreter{}.run (*expr);
222
+ std::vector<Literal> expected{Literal (float (2.0 ))};
223
+
224
+ EXPECT_EQ (results, expected);
225
+ }
0 commit comments