All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joel Cruz Cabrera <tf.joel.work@gmail.com>
To: akpm@linux-foundation.org
Cc: tpiepho@gmail.com, linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] math: rational: add a KUnit case for a semi-convergent term above LONG_MAX
Date: Tue,  1 Dec 2026 12:46:34 +0000	[thread overview]
Message-ID: <20261201124634.48970-2-tf.joel.work@gmail.com> (raw)
In-Reply-To: <20261201124634.48970-1-tf.joel.work@gmail.com>

Add a case where the best semi-convergent term is ULONG_MAX - 1, which
made "2u * t" overflow before the previous patch: for 1/ULONG_MAX with
max_denominator = ULONG_MAX - 1, the closest fraction is
1/(ULONG_MAX - 1), not 0/1.  The case is written with ULONG_MAX so that
it covers both 32-bit and 64-bit kernels.

This test was written with the help of an AI assistant (Claude, by
Anthropic); I reviewed it.




Signed-off-by: Joel Cruz Cabrera <tf.joel.work@gmail.com>
---
 lib/math/tests/rational_kunit.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lib/math/tests/rational_kunit.c b/lib/math/tests/rational_kunit.c
index 47486a95f..c8dac1904 100644
--- a/lib/math/tests/rational_kunit.c
+++ b/lib/math/tests/rational_kunit.c
@@ -2,6 +2,7 @@
 
 #include <kunit/test.h>
 
+#include <linux/limits.h>
 #include <linux/rational.h>
 
 struct rational_test_param {
@@ -21,6 +22,8 @@ static const struct rational_test_param test_parameters[] = {
 	{ 1155, 7735,	255, 255,	33, 221,   "Exact answer" },
 	{ 87, 32,	70, 32,		68, 25,    "Semiconvergent, numerator limit" },
 	{ 14533, 4626,	15000, 2400,	7433, 2366, "Semiconvergent, denominator limit" },
+	{ 1, ULONG_MAX,	ULONG_MAX, ULONG_MAX - 1,	1, ULONG_MAX - 1,
+	  "Semiconvergent, term above LONG_MAX" },
 };
 
 static void get_desc(const struct rational_test_param *param, char *desc)
-- 
2.50.1 (Apple Git-155)


  reply	other threads:[~2026-12-01 12:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 12:46 [PATCH 1/2] math: rational: avoid overflow when comparing the semi-convergent term Joel Cruz Cabrera
2026-12-01 12:46 ` Joel Cruz Cabrera [this message]
2026-12-01 18:54   ` [PATCH 2/2] math: rational: add a KUnit case for a semi-convergent term above LONG_MAX Trent Piepho

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201124634.48970-2-tf.joel.work@gmail.com \
    --to=tf.joel.work@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tpiepho@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.