FastLED 3.10.6
Loading...
Searching...
No Matches

◆ format_floating()

void fl::printf_detail::format_floating ( sstream & stream,
const FormatSpec & spec,
const ScalarArg & a )

Definition at line 176 of file stdio.cpp.hpp.

176 {
178 bool is_numeric = false;
179
180 switch (spec.type) {
181 case 'd':
182 case 'i':
183 case 'u':
184 case 'o':
185 case 'c':
186 result = "<type_error>";
187 break;
188
189 case 'x': {
190 is_numeric = true;
191 const bool is_float = a.kind == ScalarArg::kFloat;
192 result = is_float ? fl::to_hex(a.f, spec.uppercase)
193 : fl::to_hex(a.d, spec.uppercase);
194 const bool nonzero = is_float ? a.f != 0.0f : a.d != 0.0;
195 if (spec.alt_form && nonzero) {
196 result = fl::string(spec.uppercase ? "0X" : "0x") + result;
197 }
198 break;
199 }
200
201 case 'f': {
202 is_numeric = true;
203 const float value =
204 a.kind == ScalarArg::kFloat ? a.f : static_cast<float>(a.d);
205 if (spec.precision >= 0) {
207 } else {
208 sstream temp;
209 temp << value;
210 result = temp.str();
211 }
212 break;
213 }
214
215 case 's': {
216 sstream temp;
217 stream_floating(temp, a);
218 result = temp.str();
219 break;
220 }
221
222 default:
223 result = "<unknown_format>";
224 break;
225 }
226 emit_padded(stream, spec, result, is_numeric);
227}
void stream_floating(sstream &temp, const ScalarArg &a) FL_NO_EXCEPT
Definition stdio.cpp.hpp:76
void emit_padded(sstream &stream, const FormatSpec &spec, const fl::string &result, bool is_numeric) FL_NO_EXCEPT
Definition stdio.cpp.hpp:84
fl::string format_float(float value, int precision) FL_NO_EXCEPT
Definition stdio.h:341
constexpr int type_rank< T >::value
fl::string to_hex(T value, bool uppercase=false, bool pad_to_width=false) FL_NO_EXCEPT
Convert an integer value to hexadecimal string representation.
Definition string.h:526
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31
Base definition for an LED controller.
Definition crgb.hpp:179

References fl::FL_NO_EXCEPT, format_float(), fl::printf_detail::ScalarArg::kFloat, fl::sstream::str(), fl::to_hex(), and fl::type_rank< T >::value.

Referenced by format_scalar_arg().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: