Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

printf: Fix floating-point rounding consistency for RTZ devices #2202

Merged
merged 2 commits into from
Feb 11, 2025

Conversation

cycheng
Copy link
Contributor

@cycheng cycheng commented Dec 25, 2024

  1. In vector test, prepare RTZ answer for RTZ rounding.

  2. In mixed_format_random test, for a given float 'arg', the test previously used 'arg' directly to generate ref_str:

      ref_str << str_sprintf(format, arg);
    

    This approach incorrectly assumes:

      (float) arg == to_fp(to_str(arg));
    

    However, this assumption fails under RTZ rounding. For example:

      arg = 0xC642549C 
      to_str(arg) = -12437.152343f 
      to_fp_rtz(-12437.152343f) = 0xC642549B (-0X1.84A936P+13) 
      to_fp_rte(-12437.152343f) = 0xC642549C (-0X1.84A938P+13)
    

    To address this, the reference result is now computed based on the literal float string rather than the original 'arg' value.

1. In vector test, prepare RTZ answer for RTZ rounding.

2. In mixed_format_random test, for a given float 'arg', the test
   previously used 'arg' directly to generate ref_str:
     ref_str << str_sprintf(format, arg);

   This approach incorrectly assumes:
     (float) arg == to_fp(to_str(arg));

   However, this assumption fails under RTZ rounding. For example:
     arg = 0xC642549C
     to_str(arg) = -12437.152343f
     to_fp_rtz(-12437.152343f) = 0xC642549B (-0X1.84A936P+13)
     to_fp_rte(-12437.152343f) = 0xC642549C (-0X1.84A938P+13)

   To address this, the reference result is now computed based on the
   literal float string rather than the original 'arg' value.
@lakshmih
Copy link
Contributor

Reviewing

@bashbaug
Copy link
Contributor

Merging as discussed in the February 11th teleconference.

@bashbaug bashbaug merged commit 54afc2e into KhronosGroup:main Feb 11, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants