Comments (6)
It seems that
std::to_chars
returnserrc::value_too_large
rather thanerrc::result_out_of_range
. Is this simply a mistake or do you have a reason for usingerrc::result_out_of_range
instead?
That's how std::to_chars
is specified, and it's consistent with POSIX error handling. ERANGE is when a result can't fit in the range of the numeric output; EOVERFLOW is when there's a buffer overflow.
from charconv.
@pdimov I mean, boost::charconv::to_chars
returns errc::result_out_of_range
while std::to_chars
seems to be supposed to return errc::value_too_large
. Is there a reason for this divergence?
from charconv.
That should be a bug, then.
from charconv.
Is there a reason for this divergence?
No; it will be fixed by linked PR.
from charconv.
to_chars
with only buffer & value, with the format param as well, and with the precision param as well, all should be separate overloads. The reason why the first and the second should be separate overloads is because the first one should behave differently from the second one withfmt == chars_format::general
; it needs to select whatever representation that is shortest, which does not always need to be equal tochars_format::general
's output.
I believe the difference is between formatting with 1e-4 as the crossover point between fixed and scientific like in your last issue right? Since the goal is the absolute minimum number of characters? https://godbolt.org/z/bnscGEbMn
The reason why the second and the third should be separate overloads is because by the spec,
precision
being negative should be treated as ifprecision == 6
, because the spec ofstd::printf
says that negative precision is ignored, which means it should fall back to the default, which is 6. I guess this is quite stupid, but well, it seems that's how the spec is written anyway.
That does seem to be the case: https://godbolt.org/z/6xPMKeTcM
from charconv.
I believe the difference is between formatting with 1e-4 as the crossover point between fixed and scientific like in your last issue right? Since the goal is the absolute minimum number of characters? https://godbolt.org/z/bnscGEbMn
Yeah, 1e-4
should be printed as 1e-4
because it's shorter than 0.0001
, and similarly 1e-3
is preferred over 0.001
. But those are "easy" cases. Real headaches are the cases like the ones described in the fmt issue I linked (like 123456792.0f
, in case it was not clear).
from charconv.
Related Issues (20)
- `to_chars_hex` for __float128 incorrect exp
- buffer overflows in to_chars HOT 1
- to_chars hex FP80 HOT 10
- std::bfloat16_t and std::float16_t to_chars output exceeds type precision HOT 1
- Wrong outputs for FP given precision `to_chars` HOT 13
- Doc and README Updates Needed HOT 1
- buffer overflows in to_chars for std::bfloat16_t
- Modular Boost C++ Libraries Request HOT 1
- Build failure on GCC 4.8 and 4.9 HOT 11
- Tags linked to the Boost release version HOT 11
- Undefined symbols regarding quadmath in Alpine Linux HOT 12
- __float128 on ppc64le HOT 9
- Buffer overflow in `floff` with `chars_format::fixed` HOT 1
- from_chars & invalid input HOT 1
- Internal overflow error in `floff` HOT 1
- cmake: Incorrect `__float128` detection HOT 5
- Fail to compile on ppc64le HOT 4
- charconv2 HOT 6
- charconv cannot be built with MinGW 13.2.0 due to missing `extern "C"`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from charconv.