Use Advanced Search to search the entire archive.
Re: Just two kind to Quantity in SE-impl
- From: Martin Desruisseaux <
>
- To:
- Subject: Re: Just two kind to Quantity in SE-impl
- Date: Sun, 21 Sep 2014 22:04:58 +0200
- Organization: Geomatys
I'm fine with a "reference implementation" using BigDecimal, Long or
Double. However on my side, an implementation in production environment
would use the 'double' primitive type. But I think it is good to use
BigDecimal in the reference implementation (RI) since the purpose of RI
is to demonstrate what the results should be.
The "Effective Java" book recommendation about 'double' versus 'long'
accuracy is relevant only when base 10 has a particular meaning. The
'double' type is accurate in base 2 but not in base 10; the BigDecimal
type is accurate in base 10 but not in base 2; the 'long' type is
accurate in whatever base we choose for the divisor.
Money are usually expressed in base 10, which make BigDecimal a good
choice for such quantities. But natural quantities have no preferred
base; the mass of a person is not expressed more accurately in base 10
than in base 2, consequently BigDecimal is not a better choice than
'double' for natural quantities. AFAIK there is no "natural" integer base.
Nevertheless, many unit conversion factors are defined in base 10. For
example the conversion factor from inches to centimeters is exactly 2.54
by definition. For this reason, BigDecimal make sense for a JSR-363
reference implementation, but not necessarily for use in production
(especially for applications in natural sciences).
Martin
Le 15/09/14 03:57, Otávio Gonçalves de Santana a écrit :
>
Werner with Number in parameter in the factory, so:
>
AbstractyQuantity.of(Number number, Unit<Q> unit)
>
>
We will suport all kinds in of types used in Java, this way:
>
>
* AtomicInteger
>
* AtomicLong
>
* BigDecimal
>
* BigInteger
>
* Byte
>
* Double
>
* DoubleAccumulator
>
* DoubleAdder
>
* Float
>
* Integer
>
* Long
>
* LongAccumulator
>
* LongAdder
>
* Short
>
>
>
But internally, I would work with just two kinds:
>
>
1. BigDecimal
>
2. Long as Fastmoney or Double
>