Skip to content

fix: missing math.h for NAN #423

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

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions quickjs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.


#ifdef __cplusplus
extern "C" {
Expand Down
Loading