builtin_function*py: more test data for "trunc"

Submitted by Andres Gomez on May 3, 2016, 1:56 p.m.

Details

Message ID 1462283803-23250-1-git-send-email-agomez@igalia.com
State Accepted
Commit f3a7a0a729fcedac98563710aaa1613a26388f7a
Headers show
Series "builtin_function*py: more test data for "trunc"" ( rev: 1 ) in Piglit

Not browsing as part of any series.

Commit Message

Andres Gomez May 3, 2016, 1:56 p.m.
When performing a trunc op in a float value there is, basically, three
scenarios: when the exponent is < 0, when it is > bitsize of the
significand or with a value in the middle. Current generator was using
data for values in the middle and < 0 but not for the last case so we
add now a couple of values in that range and also the interesting 0.0
special value.

Signed-off-by: Andres Gomez <agomez@igalia.com>
---
 generated_tests/builtin_function.py      | 8 +++++++-
 generated_tests/builtin_function_fp64.py | 8 +++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/generated_tests/builtin_function.py b/generated_tests/builtin_function.py
index b587851..7cbd237 100644
--- a/generated_tests/builtin_function.py
+++ b/generated_tests/builtin_function.py
@@ -859,7 +859,13 @@  def _make_componentwise_test_vectors(test_suite_dict):
     f('sign', 1, 110, np.sign, None, [np.linspace(-1.5, 1.5, 5)])
     f('sign', 1, 130, np.sign, None, [ints])
     f('floor', 1, 110, np.floor, None, [np.linspace(-2.0, 2.0, 4)])
-    f('trunc', 1, 130, _trunc, None, [np.linspace(-2.0, 2.0, 8)])
+
+    # Note: with trunc we want to test values in which the floating
+    # point exponent is < 0, > 23 or in the middle. Hence, we append
+    # some numbers to cover all possible scenarios.
+    f('trunc', 1, 130, _trunc, None,
+      [np.append(np.linspace(-2.0, 2.0, 8),
+                 [0.0, 45027112.0, -45027112.0])])
 
     # Note: the direction of rounding used by round() is not specified
     # for half-integer values, so we test it over a range that doesn't
diff --git a/generated_tests/builtin_function_fp64.py b/generated_tests/builtin_function_fp64.py
index 7e4d3eb..af3599b 100644
--- a/generated_tests/builtin_function_fp64.py
+++ b/generated_tests/builtin_function_fp64.py
@@ -768,7 +768,13 @@  def _make_componentwise_test_vectors(test_suite_dict):
     f('abs', 1, np.abs, None, [np.linspace(-1.5, 1.5, 5)])
     f('sign', 1, np.sign, None, [np.linspace(-1.5, 1.5, 5)])
     f('floor', 1, np.floor, None, [np.linspace(-2.0, 2.0, 4)])
-    f('trunc', 1, _trunc, None, [np.linspace(-2.0, 2.0, 8)])
+
+    # Note: with trunc we want to test values in which the floating
+    # point exponent is < 0, > 52 or in the middle. Hence, we append
+    # some numbers to cover all possible scenarios.
+    f('trunc', 1, _trunc, None,
+      [np.append(np.linspace(-2.0, 2.0, 8),
+                 [0.0, 4.5027112340958570e19, -4.5027112340958570e19])])
 
     # Note: the direction of rounding used by round() is not specified
     # for half-integer values, so we test it over a range that doesn't

Comments

Andres Gomez <agomez@igalia.com> writes:

> When performing a trunc op in a float value there is, basically, three
> scenarios: when the exponent is < 0, when it is > bitsize of the
> significand or with a value in the middle. Current generator was using
> data for values in the middle and < 0 but not for the last case so we
> add now a couple of values in that range and also the interesting 0.0
> special value.

Yeah, the testing for trunc/floor/ceil are really weak.  It would also
be relevant to test values with exponents >= 32, to catch
implementations trying to use casting to an integer.

Still, improvements are good:

Reviewed-by: Eric Anholt <eric@anholt.net>
On Tue, 2016-05-03 at 12:39 -0700, Eric Anholt wrote:
> Andres Gomez <agomez@igalia.com> writes:
> 
> > 
> > When performing a trunc op in a float value there is, basically,
> > three
> > scenarios: when the exponent is < 0, when it is > bitsize of the
> > significand or with a value in the middle. Current generator was
> > using
> > data for values in the middle and < 0 but not for the last case so
> > we
> > add now a couple of values in that range and also the interesting
> > 0.0
> > special value.
> Yeah, the testing for trunc/floor/ceil are really weak.  It would
> also
> be relevant to test values with exponents >= 32, to catch
> implementations trying to use casting to an integer.

Thanks!

Yes, that makes sense. I will take that into account for a future
patch. Right now there are some problems when using very big values
regarding the tolerance calculation algorithm.

Actually, I have to send an email with doubts about the usage of the
tolerance so we can discuss about that there. Hopefully, coming soon.