niedz., 12 paź 2025 o 18:19 Matt Borland <matt@mattborland.com> napisał(a):
Precision and cohort retention are mutually exclusive
Can you explain why?
The easy answer is IEEE 754 section 5.12.2 says so.
Consider decimal32_t which has precision 7. Imagine you specify to_chars with precision of 2 and cohort retention, but the value is in the cohort that needs 4 digits. What would you print?
Hmm, I may have misunderstood the previous conversation. So let me present the use case that I have in mind. I need to represent prices in national currencies: different currencies have different number of "cents" in a "dollar": US Dollars have 100 cents in a dollar, so I need to reflect this by always displaying two digits after the decimal point, even if these are zeros. Japanese Yen uses no equivalent of "cents", so I need to display it without the comma or the fractional part. For Iraqi Dinars, one is composed of 1000 fils, so I need to always display three decimal places. My numeric values do not have to know the currency they represent, but they need to know the magnitude of the currency's subunit. They can obtain this number during initialization. Until today, I thought that my use case cannot be handled by a decimal float. But I now hear that this could be a valid use case. I am looking for the following behaviour: Decimal d{100, -2}; // "1.00" cout << d; // no formatting flags I expect this to display "1.00": I provided enough information in the initialization that the right cohort should be used so that the exact "1.00" can be recreated during printing. My question: is the above a use case intended or possible to be handled by Boost.Decimal? Irrespective of the answer, if there are any justified use cases for observing different members of a cohort, then we have an existential conflict. According to a popular concept of "regular", if two objects compare equal then any (regular) function using either of them should return the same result. Type `double` already breaks this for -0 and +0. Cohorts look like another such breakage. Regards, &rzej;