Code Monkey home page Code Monkey logo

Comments (6)

pdimov avatar pdimov commented on May 18, 2024

It seems that std::to_chars returns errc::value_too_large rather than errc::result_out_of_range. Is this simply a mistake or do you have a reason for using errc::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.

jk-jeon avatar jk-jeon commented on May 18, 2024

@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.

pdimov avatar pdimov commented on May 18, 2024

That should be a bug, then.

from charconv.

mborland avatar mborland commented on May 18, 2024

Is there a reason for this divergence?

No; it will be fixed by linked PR.

from charconv.

mborland avatar mborland commented on May 18, 2024
  1. 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 with fmt == chars_format::general; it needs to select whatever representation that is shortest, which does not always need to be equal to chars_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 if precision == 6, because the spec of std::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.

jk-jeon avatar jk-jeon commented on May 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.