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

s_roundPackToF32.c rounding to odd #20

Open
Kou66666 opened this issue Sep 11, 2023 · 2 comments
Open

s_roundPackToF32.c rounding to odd #20

Kou66666 opened this issue Sep 11, 2023 · 2 comments

Comments

@Kou66666
Copy link

Hi,

s_roundPackToF32.c, line 96 implement rounding to odd as following:

96 if ( roundingMode == softfloat_round_odd ) {
97 sig |= 1;

Does this means rod always or the fraction part bit0 to 1'b1?

The correct behavior of rod suppose to be frac round up only:

  1. round > 0.5
  2. if 0.5 & (guard bit == 0)

Kou

@aswaterman
Copy link
Member

I think you're describing a different rounding mode. Round to odd always makes the result odd if the amount rounded off is nonzero.

@Kou66666
Copy link
Author

Hi Waterman,

Thanks for your reply. u are right with rounding to odd.

Another question is how to deal with overflow with rounding to odd.

s_roundPackToF32.c, line 58 ~ 64, It seems roundIncrement take 0 in case of rod.
then line 86, rod overflow will output infinite minus 1(! roundIncrement) e.g. the largest finite value.

IEEE754 defines the overflow value with other rounding mode, but without rod. How to know rod will take the largest finite value for overflow instead of infinite?

Thanks,
Kou

86 uiZ = packToF32UI( sign, 0xFF, 0 ) - ! roundIncrement;
87 goto uiZ;

58 if ( ! roundNearEven && (roundingMode != softfloat_round_near_maxMag) ) {
roundIncrement =
(roundingMode
== (sign ? softfloat_round_min : softfloat_round_max))
? 0x7F
: 0;
64 }

IEEE754-2019, page 53:
a) roundTiesToEven and roundTiesToAway carry all overflows to ∞ with the sign of the
intermediate result.
b) roundTowardZero carries all overflows to the format’s largest finite number with the sign of the
intermediate result.
c) roundTowardNegative carries positive overflows to the format’s largest finite number, and carries
negative overflows to −∞.
d) roundTowardPositive carries negative overflows to the format’s most negative finite number, and
carries positive overflows to +∞.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants