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

fix: missing math.h for NAN #423

Merged
merged 1 commit into from
Jun 6, 2024
Merged

Conversation

neko-para
Copy link
Contributor

According to cppreference, NAN macro in defined in math.h.

#define JS_FLOAT64_NAN NAN

https://en.cppreference.com/w/cpp/numeric/math/NAN
https://en.cppreference.com/w/c/numeric/math/NAN

@saghul
Copy link
Contributor

saghul commented Jun 6, 2024

Is there a way to test these? Would compiling with g++ fail without this?

@neko-para
Copy link
Contributor Author

Is there a way to test these? Would compiling with g++ fail without this?

Yes, our CI failed on ubuntu building with gcc.
https://github.com/MaaXYZ/MaaFramework/actions/runs/9386698680/job/25847908600

@neko-para
Copy link
Contributor Author

neko-para commented Jun 6, 2024

godbolt reproduce

@saghul saghul merged commit 22c1022 into quickjs-ng:master Jun 6, 2024
47 checks passed
@saghul
Copy link
Contributor

saghul commented Jun 6, 2024

Cheers!

@chqrlie chqrlie self-requested a review June 6, 2024 09:35
chqrlie

This comment was marked as outdated.

@@ -30,6 +30,7 @@
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <math.h>
Copy link
Collaborator

@chqrlie chqrlie Jun 6, 2024

Choose a reason for hiding this comment

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

Simple fix! I'm surprised this problem did not surface before.

Note however that as of c2x, NAN is now also defined in <float.h> as specified in 5.2.4.2.2 Characteristics of floating types <float.h> and the standard says:

Use of the macros INFINITY, DEC_INFINITY, NAN, and DEC_NAN in <math.h> is an obsolescent
feature. Instead, use the same macros in <float.h>.

This suggests including <float.h> instead of <math.h> or at least in addition to <math.h>, but gcc needs the option -std=c2x to allow using NAN with just <float.h> included so just including <math.h> is portable and should remain valid for a few more decades.

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

3 participants