diff mbox series

[11/23] math: Add inf support on gen-auto-libm-tests.c

Message ID 20241129132032.476978-12-adhemerval.zanella@linaro.org
State New
Headers show
Series Add remaining CORE-MATH binary32 implementations to libm | expand

Commit Message

Adhemerval Zanella Netto Nov. 29, 2024, 1:17 p.m. UTC
For some correctly rounded inputs where infinity might generate
a number (like atanf), comparing to a pre-defined constant does not
yield the expected result in all roundind modes.

The most straightforward way to handle it would be to get the expected
result from mpfr, where it handles all the rounding mode.
---
 math/gen-auto-libm-tests.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

Comments

Joseph Myers Nov. 29, 2024, 4:35 p.m. UTC | #1
On Fri, 29 Nov 2024, Adhemerval Zanella wrote:

> For some correctly rounded inputs where infinity might generate
> a number (like atanf), comparing to a pre-defined constant does not
> yield the expected result in all roundind modes.
> 
> The most straightforward way to handle it would be to get the expected
> result from mpfr, where it handles all the rounding mode.

This is missing updates to the comment at the top of gen-auto-libm-tests.c 
("Inputs are either finite real numbers or ...") to explain the handling 
of infinities.
Adhemerval Zanella Netto Dec. 3, 2024, 6:51 p.m. UTC | #2
On 29/11/24 13:35, Joseph Myers wrote:
> On Fri, 29 Nov 2024, Adhemerval Zanella wrote:
> 
>> For some correctly rounded inputs where infinity might generate
>> a number (like atanf), comparing to a pre-defined constant does not
>> yield the expected result in all roundind modes.
>>
>> The most straightforward way to handle it would be to get the expected
>> result from mpfr, where it handles all the rounding mode.
> 
> This is missing updates to the comment at the top of gen-auto-libm-tests.c 
> ("Inputs are either finite real numbers or ...") to explain the handling 
> of infinities.
> 

Right, I changed to:

   Other lines are test lines, of the form "function input1 input2
   ... [flag1 flag2 ...]".  Inputs are either finite real numbers,
   positive or negative infinite (in the form of "inf" or "-inf"), or
   integers, depending on the function under test.  Real numbers may be
   in any form acceptable to mpfr_strtofr  (base 0), infinite may in any
   form acceptable to mpfr_set_inf, and integers in any form acceptable
   to mpz_set_str (base 0).  In addition, real numbers may be certain
   special strings such as "pi", as listed in the special_real_inputs
   array.
diff mbox series

Patch

diff --git a/math/gen-auto-libm-tests.c b/math/gen-auto-libm-tests.c
index 0b1e307fae..457610ef04 100644
--- a/math/gen-auto-libm-tests.c
+++ b/math/gen-auto-libm-tests.c
@@ -981,6 +981,26 @@  special_fill_e_minus_1 (mpfr_t res0, mpfr_t res1, fp_format format)
   return 2;
 }
 
+/* Set the precision of RES0 based on FORMAT and initialize as an
+   infinite number.  */
+static size_t
+special_fill_inf (mpfr_t res0, mpfr_t res1 __attribute__ ((unused)),
+		  fp_format format)
+{
+  mpfr_init2 (res0, fp_formats[format].mant_dig);
+  mpfr_set_inf (res0, 0);
+  return 1;
+}
+
+static size_t
+special_fill_minus_inf (mpfr_t res0, mpfr_t res1 __attribute__ ((unused)),
+			fp_format format)
+{
+  mpfr_init2 (res0, fp_formats[format].mant_dig);
+  mpfr_set_inf (res0, -1);
+  return 1;
+}
+
 /* A special string accepted in input arguments.  */
 typedef struct
 {
@@ -1016,6 +1036,8 @@  static const special_real_input special_real_inputs[] =
     { "e", special_fill_e },
     { "1/e", special_fill_1_e },
     { "e-1", special_fill_e_minus_1 },
+    { "inf", special_fill_inf },
+    { "-inf", special_fill_minus_inf },
   };
 
 /* Given a real number R computed in round-to-zero mode, set the
@@ -1062,7 +1084,6 @@  round_real (mpfr_t res[rm_num_modes],
 	    unsigned int exc_after[rm_num_modes],
 	    mpfr_t r, fp_format format)
 {
-  assert (mpfr_number_p (r));
   for (rounding_mode m = rm_first_mode; m < rm_num_modes; m++)
     {
       mpfr_init2 (res[m], fp_formats[format].mant_dig);