--- a/src/cairo-pen.c	2022-03-30 09:48:14.702456922 +0100
+++ b/src/cairo-pen.c	2022-03-30 09:50:40.011793460 +0100
@@ -289,7 +289,12 @@
     } else if (tolerance >= major_axis) {
 	num_vertices = 4;
     } else {
-	num_vertices = ceil (2*M_PI / acos (1 - tolerance / major_axis));
+	double divisor = acos (1 - tolerance / major_axis);
+
+	if (divisor == 0.0)
+	    return 4;
+
+	num_vertices = ceil (2*M_PI / divisor);
 
 	/* number of vertices must be even */
 	if (num_vertices % 2)
