1
1
/*
2
- Print.cpp - Base class that provides print() and println()
3
- Copyright (c) 2008 David A. Mellis. All right reserved.
4
-
5
- This library is free software; you can redistribute it and/or
6
- modify it under the terms of the GNU Lesser General Public
7
- License as published by the Free Software Foundation; either
8
- version 2.1 of the License, or (at your option) any later version.
9
-
10
- This library is distributed in the hope that it will be useful,
11
- but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
- Lesser General Public License for more details.
14
-
15
- You should have received a copy of the GNU Lesser General Public
16
- License along with this library; if not, write to the Free Software
17
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
-
19
- Modified 23 November 2006 by David A. Mellis
20
- */
2
+ Copyright (c) 2014 Arduino. All right reserved.
3
+
4
+ This library is free software; you can redistribute it and/or
5
+ modify it under the terms of the GNU Lesser General Public
6
+ License as published by the Free Software Foundation; either
7
+ version 2.1 of the License, or (at your option) any later version.
8
+
9
+ This library is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ See the GNU Lesser General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Lesser General Public
15
+ License along with this library; if not, write to the Free Software
16
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
+ */
21
18
22
19
#include < stdlib.h>
23
20
#include < stdio.h>
@@ -211,15 +208,15 @@ size_t Print::printNumber(unsigned long n, uint8_t base) {
211
208
return write (str);
212
209
}
213
210
214
- size_t Print::printFloat (double number, uint8_t digits)
215
- {
211
+ size_t Print::printFloat (double number, uint8_t digits)
212
+ {
216
213
size_t n = 0 ;
217
-
214
+
218
215
if (isnan (number)) return print (" nan" );
219
216
if (isinf (number)) return print (" inf" );
220
217
if (number > 4294967040.0 ) return print (" ovf" ); // constant determined empirically
221
218
if (number <-4294967040.0 ) return print (" ovf" ); // constant determined empirically
222
-
219
+
223
220
// Handle negative numbers
224
221
if (number < 0.0 )
225
222
{
@@ -231,7 +228,7 @@ size_t Print::printFloat(double number, uint8_t digits)
231
228
double rounding = 0.5 ;
232
229
for (uint8_t i=0 ; i<digits; ++i)
233
230
rounding /= 10.0 ;
234
-
231
+
235
232
number += rounding;
236
233
237
234
// Extract the integer part of the number and print it
@@ -241,7 +238,7 @@ size_t Print::printFloat(double number, uint8_t digits)
241
238
242
239
// Print the decimal point, but only if there are digits beyond
243
240
if (digits > 0 ) {
244
- n += print (" ." );
241
+ n += print (" ." );
245
242
}
246
243
247
244
// Extract digits from the remainder one at a time
@@ -250,8 +247,8 @@ size_t Print::printFloat(double number, uint8_t digits)
250
247
remainder *= 10.0 ;
251
248
int toPrint = int (remainder );
252
249
n += print (toPrint);
253
- remainder -= toPrint;
254
- }
255
-
250
+ remainder -= toPrint;
251
+ }
252
+
256
253
return n;
257
254
}
0 commit comments