Skip to content

Commit f68d450

Browse files
committed
fix OSX compilation / portability errors
1 parent 2092388 commit f68d450

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1414
### Removed
1515

1616
### Fixed
17+
- Compile errors / portability issues in `WString.h` and `Print.h`, first reported by `dfrencham` on GitHub
1718

1819
### Security
1920

cpp/arduino/Print.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <stdio.h>
4+
#include <avr/pgmspace.h>
45
#include "WString.h"
56

67
#define DEC 10

cpp/arduino/WString.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@
99

1010
typedef std::string string;
1111

12+
// work around some portability issues
13+
#if defined(__clang__)
14+
#define ARDUINOCI_ISNAN ::isnan
15+
#define ARDUINOCI_ISINF ::isinf
16+
#elif defined(__GNUC__) || defined(__GNUG__)
17+
#define ARDUINOCI_ISNAN std::isnan
18+
#define ARDUINOCI_ISINF std::isinf
19+
#elif defined(_MSC_VER)
20+
// TODO: no idea
21+
#define ARDUINOCI_ISNAN ::isnan
22+
#define ARDUINOCI_ISINF ::isinf
23+
#else
24+
#define ARDUINOCI_ISNAN ::isnan
25+
#define ARDUINOCI_ISINF ::isinf
26+
#endif
27+
1228
class __FlashStringHelper;
1329
#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))
1430

@@ -36,8 +52,8 @@ class String: public string
3652

3753
static string dtoas(double val, int decimalPlaces) {
3854
double r = 0.5 * pow(0.1, decimalPlaces); // make sure that integer truncation will properly round
39-
if (std::isnan(val)) return "nan";
40-
if (std::isinf(val)) return "inf";
55+
if (ARDUINOCI_ISNAN(val)) return "nan";
56+
if (ARDUINOCI_ISINF(val)) return "inf";
4157
val += val > 0 ? r : -r;
4258
if (val > 4294967040.0) return "ovf";
4359
if (val <-4294967040.0) return "ovf";

0 commit comments

Comments
 (0)