From a341b7c346fec3dacccf1f06ed52c690466bfd30 Mon Sep 17 00:00:00 2001 From: Erik Strand <erik.strand@cba.mit.edu> Date: Thu, 12 Nov 2020 16:18:07 -0500 Subject: [PATCH] Break the example code --- gdb/README.md | 3 +++ gdb/main.cpp | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/gdb/README.md b/gdb/README.md index a9b6a61..bc275bb 100644 --- a/gdb/README.md +++ b/gdb/README.md @@ -21,6 +21,9 @@ build it from [source](https://www.gnu.org/software/gdb/current/). ## Debugging on Your Computer +Let's try running the example program in this directory. It should tell us which numbers are prime. +But there seems to be a problem. + ## Debugging on Your Microcontroller I'll refrain from diff --git a/gdb/main.cpp b/gdb/main.cpp index fb3a887..33fd700 100644 --- a/gdb/main.cpp +++ b/gdb/main.cpp @@ -1,8 +1,9 @@ #include <iostream> +#include <cmath> // This is a simple function that checks if numbers are prime. Or does it? There may be a bug... bool is_prime(int x) { - for (int i = 2; i < x / 2; ++i) { + for (int i = 2; i < std::sqrt(x); ++i) { if (x % i == 0) { return false; } -- GitLab