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

flamenco/tests: fix double normal classification #1848

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

anarcheuz
Copy link
Collaborator

@anarcheuz anarcheuz commented May 13, 2024

Tested by differential fuzzing with C++'s std::isnormal(). Without the fix we would reject normal double such as 0x93da8e that comes from the fuzzer (ie. lower coverage) whereas std::normal() would accept it. -ffast-math prevents us from using std::isnormal().

Note: We are purposely not rejecting 0, because it is an interesting value from a fuzzing perspective. With @ripatel-fd we suggest to change the harnesses to accept 0 as a valid fuzzing value.

@@ -97,7 +97,7 @@ static int
fd_double_is_normal( double dbl ) {
ulong x = fd_dblbits( dbl );
int is_denorm =
( fd_dblbits_bexp( x ) == 0 ) |
( fd_dblbits_bexp( x ) == 0 ) &
( fd_dblbits_mant( x ) != 0 );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function seems like it would mistakenly classify 0 as a normal number. Could you please double check that? If so then this line can be removed, or we should add another case that explicitly checks for 0 (for neatness)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anarcheuz it would be good to add a comment here explaining that we are explicitly allowing zero, and the reason.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on my reading of what I find on the Internet, 0 is not a subnormal number

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ptaffet-jump That is true, but the C/C++ definition of "isnormal" is "not a NaN, not infinity, not subnormal, and not zero". It was my mistake to not put the "is_zero" check into fd_double_is_normal.

Copy link
Collaborator

@topointon-jump topointon-jump left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, could we not merge this until Agave also accepts 0?

@@ -97,7 +97,7 @@ static int
fd_double_is_normal( double dbl ) {
ulong x = fd_dblbits( dbl );
int is_denorm =
( fd_dblbits_bexp( x ) == 0 ) |
( fd_dblbits_bexp( x ) == 0 ) &
( fd_dblbits_mant( x ) != 0 );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anarcheuz it would be good to add a comment here explaining that we are explicitly allowing zero, and the reason.

@ptaffet-jump
Copy link
Contributor

Would you also mind changing the commit message? How about flamenco/tests: fix double normal classification.

@anarcheuz anarcheuz changed the title fix | into & (allowing 0) flamenco/tests: fix double normal classification May 29, 2024
@anarcheuz
Copy link
Collaborator Author

Would you also mind changing the commit message? How about flamenco/tests: fix double normal classification.

Done.

@anarcheuz
Copy link
Collaborator Author

Looks good, could we not merge this until Agave also accepts 0?

@mjain-jump I think you mentioned that Agave accepts 0 (ie. not causing mismatch)?

Other than that, 0 is a good "magic" value for fuzzing. If Agave is also not checking for 0 we should not constrain our harness to only accept normal floating points. Especially since this check only exists in our harness and is not in production code.

@mjain-jump
Copy link
Contributor

Looks good, could we not merge this until Agave also accepts 0?

@mjain-jump I think you mentioned that Agave accepts 0 (ie. not causing mismatch)?

Other than that, 0 is a good "magic" value for fuzzing. If Agave is also not checking for 0 we should not constrain our harness to only accept normal floating points. Especially since this check only exists in our harness and is not in production code.

Agave indeed seems to be accepting 0.

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

Successfully merging this pull request may close these issues.

None yet

5 participants