Skip to content

Commit 99df55c

Browse files
authored
Merge pull request #62 from sakuraio/check-sizeof-double
Check sizeof(double)
2 parents 99587b2 + b21593f commit 99df55c

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ Please see example code.
167167
* [Shell](./examples/Shell/Shell.ino)
168168
* [Send illminance (CdS)](./examples/CdS/CdS.ino)
169169

170+
# Notes
170171

172+
* On the Uno and other ATMEGA based boards, Values ​​of type double are sent as float type. (Please see [Arduino Reference]( https://www.arduino.cc/reference/en/language/variables/data-types/double/).)
171173

172174
# License
173175

src/SakuraIO.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,18 @@ uint8_t SakuraIO::enqueueTx(uint8_t ch, float value, uint64_t offset){
164164
}
165165

166166
uint8_t SakuraIO::enqueueTx(uint8_t ch, double value, uint64_t offset){
167+
168+
// check sizeof(double)
169+
//
170+
// On the Uno and other ATMEGA based boards,
171+
// this occupies 4 bytes. That is, the double
172+
// implementation is exactly the same as the float,
173+
// with no gain in precision.
174+
// https://www.arduino.cc/reference/en/language/variables/data-types/double/
175+
if (sizeof(double) == 4){
176+
return enqueueTx(ch, (float)value, offset);
177+
}
178+
167179
return enqueueTxRaw(ch, 'd', 8, (uint8_t *)&value, offset);
168180
}
169181

0 commit comments

Comments
 (0)