mirror of
https://github.com/genodelabs/genode.git
synced 2025-02-07 11:50:24 +00:00
parent
f81d4cfbbb
commit
acd2a40076
@ -120,6 +120,16 @@ namespace Genode {
|
|||||||
print(output, (int)value);
|
print(output, (int)value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print single-precision float
|
||||||
|
*/
|
||||||
|
void print(Output &output, float);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print double-precision float
|
||||||
|
*/
|
||||||
|
void print(Output &output, double);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper for the hexadecimal output of integer values
|
* Helper for the hexadecimal output of integer values
|
||||||
*
|
*
|
||||||
|
@ -108,6 +108,39 @@ static inline void out_unsigned(T value, unsigned base, int pad,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Output floating point value
|
||||||
|
*/
|
||||||
|
template <typename T, typename OUT_CHAR_FN>
|
||||||
|
static inline void out_float(T value, unsigned base, unsigned length, OUT_CHAR_FN const &out_char)
|
||||||
|
{
|
||||||
|
/* set flag if value is negative */
|
||||||
|
int neg = value < 0 ? 1 : 0;
|
||||||
|
|
||||||
|
/* get absolute value */
|
||||||
|
value = value < 0 ? -value : value;
|
||||||
|
|
||||||
|
uint64_t integer = (uint64_t)value;
|
||||||
|
|
||||||
|
if (neg)
|
||||||
|
out_char('-');
|
||||||
|
|
||||||
|
out_unsigned(integer, base, 0, out_char);
|
||||||
|
out_char('.');
|
||||||
|
|
||||||
|
if (length) {
|
||||||
|
do {
|
||||||
|
value -= integer;
|
||||||
|
value = value*base;
|
||||||
|
|
||||||
|
integer = (int64_t)value;
|
||||||
|
out_char(ascii(integer));
|
||||||
|
|
||||||
|
length--;
|
||||||
|
} while (length && (value > 0.0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
namespace Genode { template <size_t, typename> class Buffered_output; }
|
namespace Genode { template <size_t, typename> class Buffered_output; }
|
||||||
|
|
||||||
|
|
||||||
|
@ -75,6 +75,15 @@ void Genode::print(Output &output, long long value)
|
|||||||
out_signed<long long>(value, 10, [&] (char c) { output.out_char(c); });
|
out_signed<long long>(value, 10, [&] (char c) { output.out_char(c); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Genode::print(Output &output, float value)
|
||||||
|
{
|
||||||
|
out_float<float>(value, 10, 3, [&] (char c) { output.out_char(c); });
|
||||||
|
}
|
||||||
|
|
||||||
|
void Genode::print(Output &output, double value)
|
||||||
|
{
|
||||||
|
out_float<double>(value, 10, 6, [&] (char c) { output.out_char(c); });
|
||||||
|
}
|
||||||
|
|
||||||
void Genode::print(Output &output, Hex const &value)
|
void Genode::print(Output &output, Hex const &value)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user