Skip to content

Conversation

@martinbudden
Copy link

Fixes warning that occurs when compiled with -Wfloat-conversion.

@greiman
Copy link
Owner

greiman commented Sep 13, 2025

I will handle this fix like the fix for istream. Please try the following at line 92 of ostream,cpp:

  n += roundDbl;
  uint32_t intPart = static_cast<uint32_t>(n);  // << here
  double fractionPart = n - intPart;

I will apply it to SdFat-beta and later to the release version of SdFat.

@greiman
Copy link
Owner

greiman commented Sep 13, 2025

Few people use the iostream part of SdFat and printf is not in many board packages.

I don't use iostream much so I am playing with a variadic wrapper for anything derived from Print for my use.

Here is an early test:

VaPrint vp(Serial);

void test() {
  bool b = true;
  uint32_t x = 123456;
  vp.vprintln("x: ", x, Base(16, 'x'), ", " ,x ,Base(), ", ",  x);
  vp.vprintln('|', Width(20), 1234, '|');
  vp.vprintln('|', Width(-20), 1234, '|');
  vp.vprintln("PI: ", PI,  ", ", Prec(7), PI);
  vp.vprintln("bool b: ",  b);
} 

Width() is like iostreams std::setw(), it only applies to the next field. Base() is like iosteram std::hex and std::dec, and Prec() is like std::setprecision().

Here is the output:

x: 123456, 0x1E240, 123456
|                1234|
|1234                |
PI: 3.14, 3.1415927
bool b: true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants