Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/modules/ROOT/pages/charconv.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ Per IEEE 754 specifying both a precision and cohort preservation is an invalid o
This follows because you are potentially rounding the number, or adding trailing zeros to the fraction which both destroy the cohort information.
When using `cohort_preserving_fixed` the function will also return `{last, std::errc::invalid_argument}` for any value with a positive exponent, since rendering it in fixed notation would require appending trailing zeros.

With the `general` format, a precision gives the same result as `printf` with `%.*g`: the precision is the number of significant digits (0 counts as 1), the fixed format is used when the decimal exponent is at least -4 and less than the precision, and trailing zeros are removed.

IMPORTANT: Same as `from_chars`, `boost::decimal::to_chars` will return a `std::to_chars_result` if `std::chars_format` is used to specify the format; otherwise it returns a `boost::decimal::to_chars_result`.

The library offers an additional feature for sizing buffers without specified precision and in general format
Expand Down
10 changes: 8 additions & 2 deletions doc/modules/ROOT/pages/cstdio.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ int printf(const char* format, Dec... values) noexcept;
----

These functions are limited in their support to only decimal floating point types, and are not a complete replacement for their `std::` equivalents.
Like `std::snprintf`, `snprintf` writes as many characters as fit in the buffer, followed by a null terminator when `buf_size` is not 0, and returns the length of the full output.
If a conversion has no value, the functions return -1 and set `errno` to `EINVAL`.

== Type Modifiers

Expand All @@ -44,10 +46,14 @@ The remaining specifications of cstdio are the same as usual:

- "g" or "G" for general format
- "e" or "E" for scientific format
- "f" for fixed format
- "f" or "F" for fixed format
- "a" or "A" for hex format

NOTE: The uppercase format will return with all applicable values in uppercase (e.g. 3.14E+02 vs 3.14e+02)
NOTE: The uppercase format will return with all applicable values in uppercase (e.g. 3.14E+02 vs 3.14e+02, and INF vs inf)

A conversion can also have the flags "-", "+", " " and "0", and a minimum field width, before the precision (e.g. "%+010.3Df").
"%%" writes a single "%".
A conversion without a precision uses 6, but "a" and "A" without a precision print the exact value.

== Examples

Expand Down
15 changes: 12 additions & 3 deletions doc/modules/ROOT/pages/format.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ Format is supported when using C++20 and a compiler with appropriate support: GC

== Locale Modifier

If a format string begins with "L" the current global locale will be applied.
If the format specifier has an "L" before the type, for example `{:.2Lf}`, the locale of the call is applied: the locale given to `std::format(loc, ...)` or `fmt::format(loc, ...)`, or else the current global locale.
An "L" after the type, for example `{:.2fL}`, is also accepted.
This can be set as so:

[source, c++]
Expand Down Expand Up @@ -43,11 +44,13 @@ The following type modifiers are the same as those used by built-in floating poi
| Modifier | Format
| "g" or "G" | General
| "e" or "E" | Scientific
| "f" | Fixed
| "f" or "F" | Fixed
| "x" or "X" | Hex
| "a" or "A" | Cohort Preserving Scientific
|===

The fast types do not keep a cohort, so "a" and "A" give a `format_error` for them.

Example usage for scientific format would be: `{:e}`

NOTE: The uppercase format will return with all applicable values in uppercase (e.g. 3.14E+02 vs 3.14e+02)
Expand All @@ -57,6 +60,9 @@ NOTE: The uppercase format will return with all applicable values in uppercase (
Precision can be specified in the same way as built-in floating point values.
For example a scientific format with 3 digits or precision would be: `{:.3e}`

Without a precision, "f" and "e" give the shortest form that keeps the value (`{:f}` of 1.5 gives "1.5"), where a built-in floating point value gives 6 digits after the point.
A width or a precision above `INT_MAX` gives a `format_error`.

== Padding Modifiers

If you want all values to be printed with a fixed width padding is allowed before the precision modifier.
Expand All @@ -67,6 +73,9 @@ For example with `{:10.3e}`:

Note the space at the front of these string to keep with width at 10 characters

A `0` before the width pads with zeros after the sign, for example `{:08.2f}` gives "-0003.14" for -3.14.
An alignment overrides the `0`, and infinity and NaN are padded with spaces.

== String Literal Support

If you want the result to be a different string width than `char` you can specify this with the format string.
Expand All @@ -80,7 +89,7 @@ IMPORTANT: `std::format` only supports `char` and `wchar_t` types per the pass:[

The appropriate order for the full format specifier is:

String literal pass:["{Sign, Padding, Precision, Type, Locale}"]
String literal pass:["{Fill and Alignment, Sign, 0, Width, Precision, Locale, Type}"]

== Examples

Expand Down
4 changes: 4 additions & 0 deletions doc/modules/ROOT/pages/generic_decimal.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ In the event of binary arithmetic between two decimal types the result will be t

xref:design.adoc#non-finite-deviation[Non-finite values are supported]

== 3.2.11 Note

`operator<<` uses the stream flags as for a `double`: the float field (`fixed`, `scientific` or `hexfloat`), the precision, `showpos`, `showpoint`, `uppercase`, the width, fill and adjustment, and the grouping and decimal point of the `std::numpunct` of the stream character type. An exception during the output sets `badbit`, and goes to the caller only when `badbit` is in the exception mask.

[#operator_behavior]
== Operator Behaviors

Expand Down
Loading
Loading