On Wed, 22 Feb 2012, Jan Burse wrote:
> If a decimal scale suits you, you could use:
>
> http://docs.oracle.com/javase/7/docs...igDecimal.html
Decimal would be fine. BigDecimal might actually be okay too.
I've actually misrepresented the context for this question slightly. My
current place of work does a few calculations, and we currently use a
fixed-point implementation of our own. However, it doesn't quite meet all
our needs. My choice is really between extending it, and replacing it with
something else. Being lazy, i would rather take advantage of someone
else's hard work than do any myself.
Now, we wrote this fixed-point implementation having previously used
BigDecimal, because we had some serious performance problems with that.
This was before my time, so i'm very hazy on the details. I had already
dismissed BigDecimal out of hand on the basis of that, but it might
actually be worth looking at again.
I'd still be interested in any existing fixed-point libraries, as another
option to consider.
tom
> Decimal scale means your numbers would be represented as:
>
> mantissa * 10 ^ -scale
>
> Bye
>
> Tom Anderson schrieb:
>
>> I would quite like to represent some numbers in fixed point, and do
>> arithmetic with them.
>>
>> These numbers will mostly not be more than a bilion, and will probably
>> never be more than a hundred billion. Some of them, i will need to
>> represent to eight decimal places. I'd like to be able to multiply two
>> large numbers, but i suspect will not need to multiply three. 11 * 2 + 8
>> = 30 decimal digits; that's about 100 bits, so 128 bits would be big
>> enough (about 5 decimal digits of headroom).
>>
>> Can anyone suggest an existing library for doing fixed-point arithmetic
>> which would cover this?
>>
>> I have googled, but not found anything. There are a few fixed-precision
>> libraries aimed at J2ME (i assume because old phones didn't have
>> floating-point units?). There's something called jExigo, but it's 64-bit
>> and the code doesn't look great.
>>
>> It's quite possible that there is no such library. But i thought it
>> prudent to ask before writing one myself.
--
X is for ... EXECUTION!