Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Io_moon by
utility.cpp
00001 #include <Blynk/BlynkDebug.h> 00002 00003 #if defined(ESP8266) && !defined(BLYNK_NO_FLOAT) 00004 #include <string.h> 00005 #include <math.h> 00006 00007 char* dtostrf_internal(double number, signed char width, unsigned char prec, char *s) { 00008 if(isnan(number)) { 00009 strcpy(s, "nan"); 00010 return s; 00011 } 00012 if(isinf(number)) { 00013 strcpy(s, "inf"); 00014 return s; 00015 } 00016 00017 if(number > 4294967040.0 || number < -4294967040.0) { 00018 strcpy(s, "ovf"); 00019 return s; 00020 } 00021 char* out = s; 00022 // Handle negative numbers 00023 if(number < 0.0) { 00024 *out = '-'; 00025 ++out; 00026 number = -number; 00027 } 00028 00029 // Round correctly so that print(1.999, 2) prints as "2.00" 00030 double rounding = 0.5; 00031 for(uint8_t i = 0; i < prec; ++i) 00032 rounding /= 10.0; 00033 00034 number += rounding; 00035 00036 // Extract the integer part of the number and print it 00037 unsigned long int_part = (unsigned long) number; 00038 double remainder = number - (double) int_part; 00039 out += sprintf(out, "%d", int_part); 00040 00041 // Print the decimal point, but only if there are digits beyond 00042 if(prec > 0) { 00043 *out = '.'; 00044 ++out; 00045 } 00046 00047 while(prec-- > 0) { 00048 remainder *= 10.0; 00049 if((int)remainder == 0){ 00050 *out = '0'; 00051 ++out; 00052 } 00053 } 00054 sprintf(out, "%d", (int) remainder); 00055 00056 return s; 00057 } 00058 00059 #endif 00060 00061
Generated on Tue Jul 19 2022 01:01:49 by
1.7.2
