Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail From: Jan Burse Newsgroups: comp.lang.java.programmer Subject: Re: Fixed-point arithmetic library Date: Wed, 22 Feb 2012 22:59:45 +0100 Organization: albasani.net Lines: 38 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.albasani.net QQEmV+j/7eGV0vrnj3BUF9iHJLVA4x77+NuVWATx1nSfDz3iYTWOnK5zWLqLBEdI9+E6y7RL6g/vnOtMZcCD+9MAjeddwn7iZLrHtD1gwIWWPEpdpZJZ4g5lzdHRYjIC NNTP-Posting-Date: Wed, 22 Feb 2012 21:59:46 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="CK8pO0o13fc0inbzNRfdugv62//Lklmu+0+t/7wcOTlK487SAlXIBK5RaRINBEttWlN3Dzo/Zcv+qk5vspoHREVGxow/zz6vYeVsA/PAL+w4woTKj5zFTQyGjWYscJ6I"; mail-complaints-to="abuse@albasani.net" User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:10.0.2) Gecko/20120216 Firefox/10.0.2 SeaMonkey/2.7.2 In-Reply-To: Cancel-Lock: sha1:sfKq9XIa4XNf6tqURlZsaOu8h2I= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:12254 If a decimal scale suits you, you could use: http://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html Decimal scale means your numbers would be represented as: mantissa * 10 ^ -scale Bye Tom Anderson schrieb: > Evening all, > > 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. > > Thanks, > tom >