Module Name:    src
Committed By:   riastradh
Date:           Sun May 12 20:58:44 UTC 2024

Modified Files:
        src/tests/lib/libm: t_hypot.c

Log Message:
t_hypot: Use an ld80 test case that actually fits in ld80.

Also add comments explaining how I generated these test cases.

(No autoconf back doors hidden in these magic numbers, I promise!  No
pythagoreans were harmed in the production of these tests either.)


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/lib/libm/t_hypot.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libm/t_hypot.c
diff -u src/tests/lib/libm/t_hypot.c:1.6 src/tests/lib/libm/t_hypot.c:1.7
--- src/tests/lib/libm/t_hypot.c:1.6	Sat May 11 20:51:41 2024
+++ src/tests/lib/libm/t_hypot.c	Sun May 12 20:58:44 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: t_hypot.c,v 1.6 2024/05/11 20:51:41 riastradh Exp $ */
+/* $NetBSD: t_hypot.c,v 1.7 2024/05/12 20:58:44 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -440,6 +440,23 @@ ATF_TC_BODY(hypotl_trivial, tc)
 	}
 }
 
+/*
+ * All primitive Pythagorean triples are generated from coprime
+ * integers m > n > 0 by Euclid's formula,
+ *
+ *	a = m^2 - n^2
+ *	b = 2 m n,
+ *	c = m^2 + n^2.
+ *
+ * We test cases with various different numbers and positions of bits,
+ * generated by this formula.
+ *
+ * If you're curious, you can recover m and n from a, b, and c by
+ *
+ *	m = sqrt((a + c)/2)
+ *	n = b/2m.
+ */
+
 __CTASSERT(FLT_MANT_DIG >= 24);
 static const struct {
 	float a, b, c;
@@ -468,7 +485,7 @@ static const struct {
 	long double a, b, c;
 } exact_casesl[] = {
 	{ 3458976450080784639, 4611968592949214720, 5764960744407842561 },
-	{ 0x1ffffffff, 0x1fffffffe00000000p0L, 0x1fffffffe00000001p0L },
+	{ 0x200000000, 0x7ffffffffffffffe, 0x8000000000000002 },
 #if LDBL_MANT_DIG >= 113
 	{ 973555668229277869436257492279295.L,
 	  1298074224305703705819019479072768.L,

Reply via email to