20
20
#include < stdio.h>
21
21
#include < string.h>
22
22
#include < math.h>
23
+ #include < limits.h>
23
24
#include " Arduino.h"
24
25
25
26
#include " Print.h"
27
+ #include " ../../config.h"
26
28
27
29
// Public Methods //////////////////////////////////////////////////////////////
28
30
@@ -295,8 +297,13 @@ size_t Print::printFloat(double number, uint8_t digits)
295
297
if (isnan (number)) return print (" nan" );
296
298
if (isinf (number)) return print (" inf" );
297
299
300
+ #if defined(LONG_LONG_PRINT_FLOAT)
301
+ if (number > (double )ULONG_LONG_MAX) return print (" ovf" );
302
+ if (number < -(double )ULONG_LONG_MAX) return print (" ovf" );
303
+ #else
298
304
if (number > 4294967040.0 ) return print (" ovf" ); // constant determined empirically
299
305
if (number <-4294967040.0 ) return print (" ovf" ); // constant determined empirically
306
+ #endif
300
307
301
308
// Handle negative numbers
302
309
if (number < 0.0 )
@@ -313,7 +320,11 @@ size_t Print::printFloat(double number, uint8_t digits)
313
320
number += rounding;
314
321
315
322
// Extract the integer part of the number and print it
323
+ #if defined(LONG_LONG_PRINT_FLOAT)
324
+ unsigned long long int_part = (unsigned long long )number;
325
+ #else
316
326
unsigned long int_part = (unsigned long )number;
327
+ #endif
317
328
double remainder = number - (double )int_part;
318
329
n += print (int_part);
319
330
@@ -342,8 +353,13 @@ size_t Print::printFloat(float number, uint8_t digits)
342
353
if (isnan (number)) return print (" nan" );
343
354
if (isinf (number)) return print (" inf" );
344
355
356
+ #if defined(LONG_LONG_PRINT_FLOAT)
357
+ if (number > (float )ULONG_LONG_MAX) return print (" ovf" );
358
+ if (number < -(float )ULONG_LONG_MAX) return print (" ovf" );
359
+ #else
345
360
if (number > 4294967040.0 ) return print (" ovf" ); // constant determined empirically
346
361
if (number <-4294967040.0 ) return print (" ovf" ); // constant determined empirically
362
+ #endif
347
363
348
364
// Handle negative numbers
349
365
if (number < 0.0 )
@@ -360,7 +376,11 @@ size_t Print::printFloat(float number, uint8_t digits)
360
376
number += rounding;
361
377
362
378
// Extract the integer part of the number and print it
379
+ #if defined(LONG_LONG_PRINT_FLOAT)
380
+ unsigned long long int_part = (unsigned long long )number;
381
+ #else
363
382
unsigned long int_part = (unsigned long )number;
383
+ #endif
364
384
float remainder = number - (float )int_part;
365
385
n += print (int_part);
366
386
0 commit comments