Re: [text][geometry] DoubleFormats utility

2021-05-14 Thread Gilles Sadowski
Hi.

Le ven. 14 mai 2021 à 04:17, Matt Juntunen  a écrit :
>
> Hello,
>
> Yes, the JDK definitely has number formatting capabilities. The class that I 
> propose moving to text was designed specifically for data IO operations, 
> where large numbers of doubles need to be serialized to strings in some 
> standard, non-localized format. I was unable to find exactly what I wanted 
> for this in the JDK, so I wrote my own class. The main advantages to this 
> code are that the produced formatters are 1) completely thread-safe,

Out of curiosity, what are use-cases for this feature?

> 2) easy to use, 3) offer a range of formats, and 4) are at least as 
> performant as BigDecimal and DecimalFormat.

As a concrete discussion point, it might be interesting to post benchmarks
comparisons.

Regards,
Gilles

>> [...]

-
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org



Re: [text][geometry] DoubleFormats utility

2021-05-13 Thread Matt Juntunen
Hello,

Yes, the JDK definitely has number formatting capabilities. The class that I 
propose moving to text was designed specifically for data IO operations, where 
large numbers of doubles need to be serialized to strings in some standard, 
non-localized format. I was unable to find exactly what I wanted for this in 
the JDK, so I wrote my own class. The main advantages to this code are that the 
produced formatters are 1) completely thread-safe, 2) easy to use, 3) offer a 
range of formats, and 4) are at least as performant as BigDecimal and 
DecimalFormat.

-Matt

From: Benjamin Marwell 
Sent: Thursday, May 13, 2021 1:37 PM
To: Commons Developers List 
Subject: Re: [text][geometry] DoubleFormats utility

I'm not a commons committer, but I think it moved to Java 8, where you
already have the same functionality available in the JDK. NumberFormat and
DecimalFormat [1] will do the same already, if I am not mistaken.

Ben

1: https://www.baeldung.com/java-number-formatting




On Thu, 13 May 2021, 17:59 Matt Juntunen,  wrote:

> Hello,
>
> For the geometry IO work I did recently, I ended up creating a
> DoubleFormats [1] utility class that generates formatters for various
> floating point string representations. It creates formatters for plain
> (straight decimal), scientific, engineering, and mixed plain and scientific
> formats. A maximum number of significant decimal digits and a minimum
> exponent value can be specified for each format. Here is a simple example:
>
>
> int maxPrecision = 4;
>
> DoubleFormat plain = DoubleFormats.createPlain(maxPrecision);
> plain.format(Math.PI); // 3.142
> plain.format(-123456789); // -12350.0
> plain.format(1.23456789e-6); // 0.01235
>
> DoubleFormat eng = DoubleFormats.createEngineering(maxPrecision);
> eng.format(Math.PI); // 3.142
> eng.format(-123456789); // -123.5E6
> eng.format(1.23456789e-6); // 1.235E-6
>
>
> I currently have the methods returning a DoubleFormat functional interface
> but I plan on changing this to simply DoubleFunction.
>
> Is there any interest in moving this functionality to commons-text? I find
> it quite useful since it is thread-safe and much faster than using
> String.format or similar. I've actually created a class with much the same
> functionality for use in my day job. It would be nice if I could use
> something from commons for that.
>
> Regards,
> Matt J
>
> [1]
> https://github.com/apache/commons-geometry/blob/master/commons-geometry-io-core/src/main/java/org/apache/commons/geometry/io/core/utils/DoubleFormats.java
>
>


Re: [text][geometry] DoubleFormats utility

2021-05-13 Thread Benjamin Marwell
I'm not a commons committer, but I think it moved to Java 8, where you
already have the same functionality available in the JDK. NumberFormat and
DecimalFormat [1] will do the same already, if I am not mistaken.

Ben

1: https://www.baeldung.com/java-number-formatting




On Thu, 13 May 2021, 17:59 Matt Juntunen,  wrote:

> Hello,
>
> For the geometry IO work I did recently, I ended up creating a
> DoubleFormats [1] utility class that generates formatters for various
> floating point string representations. It creates formatters for plain
> (straight decimal), scientific, engineering, and mixed plain and scientific
> formats. A maximum number of significant decimal digits and a minimum
> exponent value can be specified for each format. Here is a simple example:
>
>
> int maxPrecision = 4;
>
> DoubleFormat plain = DoubleFormats.createPlain(maxPrecision);
> plain.format(Math.PI); // 3.142
> plain.format(-123456789); // -12350.0
> plain.format(1.23456789e-6); // 0.01235
>
> DoubleFormat eng = DoubleFormats.createEngineering(maxPrecision);
> eng.format(Math.PI); // 3.142
> eng.format(-123456789); // -123.5E6
> eng.format(1.23456789e-6); // 1.235E-6
>
>
> I currently have the methods returning a DoubleFormat functional interface
> but I plan on changing this to simply DoubleFunction.
>
> Is there any interest in moving this functionality to commons-text? I find
> it quite useful since it is thread-safe and much faster than using
> String.format or similar. I've actually created a class with much the same
> functionality for use in my day job. It would be nice if I could use
> something from commons for that.
>
> Regards,
> Matt J
>
> [1]
> https://github.com/apache/commons-geometry/blob/master/commons-geometry-io-core/src/main/java/org/apache/commons/geometry/io/core/utils/DoubleFormats.java
>
>


[text][geometry] DoubleFormats utility

2021-05-13 Thread Matt Juntunen
Hello,

For the geometry IO work I did recently, I ended up creating a DoubleFormats 
[1] utility class that generates formatters for various floating point string 
representations. It creates formatters for plain (straight decimal), 
scientific, engineering, and mixed plain and scientific formats. A maximum 
number of significant decimal digits and a minimum exponent value can be 
specified for each format. Here is a simple example:


int maxPrecision = 4;

DoubleFormat plain = DoubleFormats.createPlain(maxPrecision);
plain.format(Math.PI); // 3.142
plain.format(-123456789); // -12350.0
plain.format(1.23456789e-6); // 0.01235

DoubleFormat eng = DoubleFormats.createEngineering(maxPrecision);
eng.format(Math.PI); // 3.142
eng.format(-123456789); // -123.5E6
eng.format(1.23456789e-6); // 1.235E-6


I currently have the methods returning a DoubleFormat functional interface but 
I plan on changing this to simply DoubleFunction.

Is there any interest in moving this functionality to commons-text? I find it 
quite useful since it is thread-safe and much faster than using String.format 
or similar. I've actually created a class with much the same functionality for 
use in my day job. It would be nice if I could use something from commons for 
that.

Regards,
Matt J

[1] 
https://github.com/apache/commons-geometry/blob/master/commons-geometry-io-core/src/main/java/org/apache/commons/geometry/io/core/utils/DoubleFormats.java