osdir.com

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]# Re: [commons-numbers] [...] NUMBERS-91: Added ofInt() factory methods [...]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fractions are constructed using either ints or doubles. In the case of ints, the numerator and denominator are passed (or the denominator is assumed to be one). Constructing fractions from doubles is more algorithmic work: if I pass a known fixed quantity such as 0.6 of course it will not be hard for the constructor to determine that is the equivalent of 3 / 5 . However if doubles are being passed of unknown precision, then I may want to request a max value on the denominator, or a precision within which the simplest fraction should be returned, or even the maximum iterations in the computation. I think of those as qualitatively very different activities so I called them ofInt and ofDouble. The example I had in mind was probably Complex, where we have ofPolar and ofCartesian. I suppose you are right, in this case the hard typing of the passed variables alone could invoke either an int or double based method while with Complex, both constructors are taking doubles. You do then have some very similar methods, for example of(int a, int b) will be an integer fraction with a on top and b on bottom; while calling of(double a, int b) will produce a fraction that approximates double a with max denominator b. Those two processes are so different that it might be more clarifying to distinguish them as ofInt(int a, int b) and ofDouble(double a, int b) Eric On Fri, Dec 28, 2018 at 4:33 AM Gilles <gilles@xxxxxxxxxxxxxxxxxxxxx> wrote: > Hello Eric. > > On Thu, 27 Dec 2018 17:00:15 -0800, Eric Barnhill wrote: > > I am overloading: > > > > public static BigFraction ofInt(final BigInteger num) { > > return new BigFraction(num, BigInteger.ONE); > > } > > > > public static BigFraction ofInt(BigInteger num, BigInteger den) { > > return new BigFraction(num, den); > > } > > > > private BigFraction(BigInteger num, BigInteger den) { > > > > Did my comment not give that impression? > > I was in fact wondering why "ofInt" rather than just "of". > > Best, > Gilles > > >> [...] > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscribe@xxxxxxxxxxxxxxxxxx > For additional commands, e-mail: dev-help@xxxxxxxxxxxxxxxxxx > >

- Prev by Date:
**Re: [VOTE][LAZY] Move commons-codec to gitbox after 1.12 release.** - Next by Date:
**Re: [commons-numbers] [...] NUMBERS-91: Added ofInt() factory methods [...]** - Previous by thread:
**Re: [commons-numbers] [...] NUMBERS-91: Added ofInt() factory methods [...]** - Next by thread:
**Re: [commons-numbers] [...] NUMBERS-91: Added ofInt() factory methods [...]** - Index(es):