Skip to content

Commit 4bcdd13

Browse files
committed
When a negative parameter is fed for the number of digits then default to the default number of parameters
1 parent d616d12 commit 4bcdd13

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

api/Print.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,11 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
332332
return bytes;
333333
}
334334

335-
size_t Print::printFloat(double number, uint8_t digits)
335+
size_t Print::printFloat(double number, int digits)
336336
{
337+
if (digits < 0)
338+
digits = 2;
339+
337340
size_t n = 0;
338341

339342
if (isnan(number)) return print("nan");

api/Print.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Print
3737
int write_error;
3838
size_t printNumber(unsigned long, uint8_t);
3939
size_t printULLNumber(unsigned long long, uint8_t);
40-
size_t printFloat(double, uint8_t);
40+
size_t printFloat(double, int);
4141
protected:
4242
void setWriteError(int err = 1) { write_error = err; }
4343
public:

test/src/Print/test_print.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ TEST_CASE ("Print::print(double, int = 2)", "[Print-print-07]")
111111
WHEN("digits = 5") { mock.print(val, 5); REQUIRE(mock._str == "3.14590"); }
112112
}
113113

114+
WHEN ("digits are negative")
115+
{
116+
double const val = 3.1459;
117+
WHEN("digits = -1") { mock.print(val, -1); REQUIRE(mock._str == "3.15"); }
118+
}
119+
114120
WHEN ("val is a negative floating point value")
115121
{
116122
double const val = -3.1459;

0 commit comments

Comments
 (0)