MCPcopy Create free account
hub / github.com/csmith-project/csmith / GenerateRandomConstantInRange

Function GenerateRandomConstantInRange

src/Constant.cpp:216–245  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

214}
215
216static string
217GenerateRandomConstantInRange(const Type* type, int bound)
218{
219 assert(type->eType == eSimple);
220
221 ostringstream oss;
222 if (type->simple_type == eInt) {
223 int b = static_cast<int>(pow(2, static_cast<double>(bound) / 2));
224 int num = pure_rnd_upto(b);
225 ERROR_GUARD("");
226 bool flag = pure_rnd_flipcoin(50);
227 ERROR_GUARD("");
228 if (flag)
229 oss << num;
230 else
231 oss << "-" << num;
232 }
233 else if (type->simple_type == eUInt) {
234 int b = static_cast<int>(pow(2, static_cast<double>(bound) / 2));
235 if (b < 0)
236 b = INT_MAX;
237 int num = pure_rnd_upto(b);
238 ERROR_GUARD("");
239 oss << num;
240 }
241 else {
242 assert(0);
243 }
244 return CGOptions::mark_mutable_const() ? "(" + oss.str() + ")" : oss.str();
245}
246
247// --------------------------------------------------------------
248 /* generate a constant struct in the form of

Callers 1

Calls 2

pure_rnd_uptoFunction · 0.85
pure_rnd_flipcoinFunction · 0.85

Tested by

no test coverage detected