Skip to content

Commit 2f903d7

Browse files
committed
Use isinf on non-mingw windows
1 parent a2732af commit 2f903d7

File tree

3 files changed

+9
-18
lines changed

3 files changed

+9
-18
lines changed

include/prism/defines.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,14 @@
138138

139139
/**
140140
* isinf on POSIX systems it accepts a float, a double, or a long double.
141-
* But Windows didn't provide isinf, so we need to use _finite instead.
141+
* But mingw didn't provide an isinf macro, only an isinf function that only
142+
* accepts floats, so we need to use _finite instead.
142143
*/
143-
#ifdef _WIN32
144-
# include <float.h>
144+
#ifdef __MINGW64__
145+
#include <float.h>
146+
#define PRISM_ISINF(x) (!_finite(x))
147+
#else
148+
#define PRISM_ISINF(x) isinf(x)
145149
#endif
146150

147151
/**

src/prism.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4142,14 +4142,7 @@ pm_double_parse(pm_parser_t *parser, const pm_token_t *token) {
41424142

41434143
// If errno is set, then it should only be ERANGE. At this point we need to
41444144
// check if it's infinity (it should be).
4145-
if (
4146-
errno == ERANGE &&
4147-
#ifdef _WIN32
4148-
!_finite(value)
4149-
#else
4150-
isinf(value)
4151-
#endif
4152-
) {
4145+
if (errno == ERANGE && PRISM_ISINF(value)) {
41534146
int warn_width;
41544147
const char *ellipsis;
41554148

src/static_literals.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -501,13 +501,7 @@ pm_static_literal_inspect_node(pm_buffer_t *buffer, const pm_static_literals_met
501501
case PM_FLOAT_NODE: {
502502
const double value = ((const pm_float_node_t *) node)->value;
503503

504-
if (
505-
#ifdef _WIN32
506-
!_finite(value)
507-
#else
508-
isinf(value)
509-
#endif
510-
) {
504+
if (PRISM_ISINF(value)) {
511505
if (*node->location.start == '-') {
512506
pm_buffer_append_byte(buffer, '-');
513507
}

0 commit comments

Comments
 (0)