Skip to content

Commit

Permalink
Fix AIX compilation issue with NAN and INFINITY (#3043)
Browse files Browse the repository at this point in the history
  • Loading branch information
ayappanec authored and mattdowle committed Sep 12, 2018
1 parent 23de27c commit 5049e56
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@

10. `fintersect` failed on tables with a column called `y`, [#3034](https://github.com/Rdatatable/data.table/issues/3034). Thanks to Maxim Nazarov for reporting.

11. Compilation fails in AIX because NAN and INFINITY macros definition in AIX make them not constant literals, [#3043](https://github.com/Rdatatable/data.table/pull/3043). Thanks to Ayappan for reporting and fixing.

#### NOTES

1. The type coercion warning message has been improved, [#2989](https://github.com/Rdatatable/data.table/pull/2989). Thanks to @sarahbeeysian on [Twitter](https://twitter.com/sarahbeeysian/status/1021359529789775872) for highlighting. For example, given the follow statements:
Expand Down
13 changes: 11 additions & 2 deletions src/fread.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,16 @@ static freadMainArgs args; // global for use by DTPRINT
const char typeName[NUMTYPE][10] = {"drop", "bool8", "bool8", "bool8", "bool8", "int32", "int64", "float64", "float64", "float64", "string"};
int8_t typeSize[NUMTYPE] = { 0, 1, 1, 1, 1, 4, 8, 8, 8, 8, 8 };

// In AIX, NAN and INFINITY don't qualify as constant literals. Refer: PR #3043
// So we assign them through below init function.
static double NAND;
static double INFD;

// NAN and INFINITY constants are float, so cast to double once up front.
static const double NAND = (double)NAN;
static const double INFD = (double)INFINITY;
void init() {
NAND = (double)NAN;
INFD = (double)INFINITY;
}

typedef struct FieldParseContext {
// Pointer to the current parsing location
Expand Down Expand Up @@ -787,6 +794,7 @@ static void parse_double_extended(FieldParseContext *ctx)
const char *ch = *(ctx->ch);
double *target = (double*) ctx->targets[sizeof(double)];
bool neg, quoted;
init();
ch += (quoted = (*ch=='"'));
ch += (neg = (*ch=='-')) + (*ch=='+');

Expand Down Expand Up @@ -871,6 +879,7 @@ static void parse_double_hexadecimal(FieldParseContext *ctx)
double *target = (double*) ctx->targets[sizeof(double)];
uint64_t neg;
bool Eneg, subnormal = 0;
init();
ch += (neg = (*ch=='-')) + (*ch=='+');

if (ch[0]=='0' && (ch[1]=='x' || ch[1]=='X') &&
Expand Down

0 comments on commit 5049e56

Please sign in to comment.