Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed an overflow error caused by choosing too small a type to store variables #2

Merged
merged 1 commit into from
Aug 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/methods/nnf/NodeManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,10 @@ class NodeManager {
@param[in] nbVar, the number of variables in the problem.
*/
static NodeManager<T> *makeNodeManager(unsigned nbVar) {
if (nbVar < (1 << 8)) return new NodeManagerTyped<T, uint8_t>();
if (nbVar < (1 << 16)) return new NodeManagerTyped<T, uint16_t>();
// One bit is reserved for the sign of the variable.
// Hence, with 8 bits we can store variables from -(2⁷-1) up to 2⁷-1. Same holds for 16 and 32 bits.
if (nbVar < (1 << 7)) return new NodeManagerTyped<T, uint8_t>();
if (nbVar < (1 << 15)) return new NodeManagerTyped<T, uint16_t>();
return new NodeManagerTyped<T, uint32_t>();
} // makeNodeManager

Expand Down