Boost logo

Boost :

From: Matt Borland (matt_at_[hidden])
Date: 2024-05-16 08:38:20


> Thanks for sharing.
>

> During the boost charconv review, it was pointed out that std from_chars has a serious design defect in case of ERANGE, because the return value cannot differentiate between different range errors (value too big, too small, positive / negative, etc.), despite the information being reliably available from the parsing.
>

> IIRC boost charconv works around this by modifiying the provided value argument, which is forbidden by std.
>

> Is the same workaround used for decimal? (in which case the documentation should state this). Or should it be seen as an opportunity for fixing the from_chars interface / providing a better error reporting?
>

Yes the same workaround is applied to decimal. I will make a note in the docs about the behavior.

>

> Another note about the documentation: some examples should use literal suffixes
>

> The current way:
>

> constexpr decimal64 b {2, -1}; // 2e-1 or 0.2
>

> is pretty unreadable / ugly. Also, there should be a statement on the differences between:
>

> constexpr auto b1 = 0.2_DD;
> constexpr auto b2 = decimal64(0.2);
> constexpr auto b3 = decimal64(2, -1);
>

> I expect the first and third ones to be identical and yield precise decimal values, and the second to yield imprecise values, although i could not find a pathological case from quick tests where we would have b2 != b3.
>

Since it's a limitation of the language 0.2_DD would actually be interpreted as a decimal64(0.2L) whereas "0.2"_DD would be equivalent to decimal64(2, -1) so b1 == b2 and b2 != b3. I will annotate this potential pitfall in the docs.

Thanks for the feedback.

Matt





Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk