Skip to content

Compares involving NaN are done wrong #43072

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

Closed
tydeman mannequin opened this issue Oct 20, 2019 · 5 comments
Closed

Compares involving NaN are done wrong #43072

tydeman mannequin opened this issue Oct 20, 2019 · 5 comments
Labels
bugzilla Issues migrated from bugzilla c clang:frontend Language frontend issues, e.g. anything involving "Sema" duplicate Resolved as duplicate floating-point Floating-point math

Comments

@tydeman
Copy link
Mannequin

tydeman mannequin commented Oct 20, 2019

Bugzilla Link 43727
Version 8.0
OS Linux
CC @topperc,@DougGregor,@zygoloid,@rotateright

Extended Description

Compares (<, <=, >=, >) that involve a floating-point NaN are done wrong with
respect to raising invalid and/or being false. This is on Intel hardware.

@topperc
Copy link
Collaborator

topperc commented Oct 20, 2019

I know we don't trap for signalling nans. There is an ongoing effort to support that. But I'd be surprised if we don't return false for nans with those compares. Do you have an example?

@tydeman
Copy link
Mannequin Author

tydeman mannequin commented Oct 20, 2019

This is NOT a problem with signaling NaNs. It is a problem with quiet NaNs.

#include <stdio.h>
#include <math.h>
#include <float.h>
#include <fenv.h>

int main(void){
if( !(NAN > 0.f) ){
(void)printf("Got expected true branch\n");
}else{
(void)printf("Got bad false branch\n");
}
if( FE_INVALID & fetestexcept( FE_ALL_EXCEPT ) ){
(void)printf("Got expected invalid\n");
}else{
(void)printf("Did not get expected invalid\n");
}

return 0;
}

@rotateright
Copy link
Contributor

See C11 7.6.1/2: "If part of a program tests floating-point status flags, sets floating-point control modes, or runs under non-default mode settings, but was translated with the state for the FENV_ACCESS pragma ‘‘off’’, the behavior is undefined."

...and you should see that clang does not support that pragma if you add it to the source example. So (unfortunately) possibly a duplicate of bug #8472 ?

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
@arsenm arsenm added floating-point Floating-point math invalid Resolved as invalid, i.e. not a bug labels Aug 13, 2023
@arsenm
Copy link
Contributor

arsenm commented Aug 13, 2023

Technically need to enable FENV_ACCESS, which is only semi-supported. Duplicate #8472

@arsenm arsenm closed this as not planned Won't fix, can't repro, duplicate, stale Aug 13, 2023
@EugeneZelenko EugeneZelenko added duplicate Resolved as duplicate clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed invalid Resolved as invalid, i.e. not a bug labels Aug 14, 2023
@llvmbot
Copy link
Member

llvmbot commented Aug 14, 2023

@llvm/issue-subscribers-clang-frontend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla c clang:frontend Language frontend issues, e.g. anything involving "Sema" duplicate Resolved as duplicate floating-point Floating-point math
Projects
None yet
Development

No branches or pull requests

5 participants