Giter Club home page Giter Club logo

Comments (9)

vitaut avatar vitaut commented on June 3, 2024

Looks the same as #2155.

from fmt.

zaphod71 avatar zaphod71 commented on June 3, 2024

I don't think you can express it in a format string directly but you can use the f specifier and then remove trailing zeros and the decimal point.

[As you meant: #2155]((#2155 (comment))
Of course it works, even with printf - I would just like it to be more convenient, as would others.

The format string syntax is pretty much fixed at this point for compatibility with std::format. That said you can implement this functionality via the extension API without changes to the core library.

that it is close to the standard - is very good, but why not extend it, that does not harm the fmt library, if the standard works, but there would still be extensions, everything so far continues to work exactly....

from fmt.

zaphod71 avatar zaphod71 commented on June 3, 2024

Hi,

i implemented the new type in the current version. Do you want to see the code?

this is an example output for the double value:

	double w = -0.00000001;

	fmt::print("{{:+.3v}}={:+.3v} {{:+#.3v}}={:+#.3v}\n", w, w);
	fmt::print("{{:-.3v}}={:-.3v} {{:-#.3v}}={:-#.3v}\n", w, w);
	fmt::print("{{:.3v}}={:.3v} {{:#.3v}}={:#.3v}\n", w, w);
	fmt::print("{{:*>12.3v}}={:*>12.3v} {{:#.3v}}={:#.3v}\n", w, w);

output:

{:+.3v}=-0 {:+#.3v}=-0.
{:-.3v}=-0 {:-#.3v}=-0.
{:.3v}=0 {:#.3v}=0.
{:*>12.3v}=***********0 {:#.3v}=0.

from fmt.

zaphod71 avatar zaphod71 commented on June 3, 2024

should i make a PR to be able to present the enhancements?

from fmt.

vitaut avatar vitaut commented on June 3, 2024

No but you can post an example of a user-defined formatter that does this.

from fmt.

zaphod71 avatar zaphod71 commented on June 3, 2024

As i understand it, i can't define a user-defined formatter for a standard type like double. that's why i integrated the new type for formatting. i only have to add/change about 40 lines. everything existing should work as before.
is there a change that this change can be integrated into the library in an upcoming version?

If not, what are the reasons for this. I would be happy to start a discussion on this.

from fmt.

vitaut avatar vitaut commented on June 3, 2024

You can define a custom formatter for this via a wrapper type.

from fmt.

zaphod71 avatar zaphod71 commented on June 3, 2024

I apologise for being so harsh, I don't want to annoy anyone.
I have understood that and I know how to implement it.
What are the reasons for not including the new format type?

  • performance?
  • no standard?
  • no need?
  • no time/resources to implement?

in my use case i sometimes have more than a million double values to format. just to wrap the value in a wrapper type and then edit it in a custom formatter makes no sense and costs unnecessary performance.

the use case is quite common in industry, especially with nc machines, such as milling and turning machines, also 3d printers. it is nc code or gcode. the new format reduces the file size and is more readable.

from fmt.

vitaut avatar vitaut commented on June 3, 2024

It is important to maintain compatibility with std::format and keep the core library small. The extension API is there to support custom, possibly common, formats.

from fmt.

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.