Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4bcdd13

Browse files
committed
When a negative parameter is fed for the number of digits then default to the default number of parameters
1 parentd616d12 commit4bcdd13

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

‎api/Print.cpp‎

Lines changed: 4 additions & 1 deletion
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_tPrint::printFloat(double number,uint8_t digits)
335+
size_tPrint::printFloat(double number,int digits)
336336
{
337+
if (digits <0)
338+
digits =2;
339+
337340
size_t n =0;
338341

339342
if (isnan(number))returnprint("nan");

‎api/Print.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Print
3737
int write_error;
3838
size_tprintNumber(unsignedlong,uint8_t);
3939
size_tprintULLNumber(unsignedlonglong,uint8_t);
40-
size_tprintFloat(double,uint8_t);
40+
size_tprintFloat(double,int);
4141
protected:
4242
voidsetWriteError(int err =1) { write_error = err; }
4343
public:

‎test/src/Print/test_print.cpp‎

Lines changed: 6 additions & 0 deletions
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+
doubleconst 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
doubleconst val = -3.1459;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp