Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #12282

Re: Fixed-point arithmetic library

From Robert Klemme <shortcutter@googlemail.com>
Newsgroups comp.lang.java.programmer
Subject Re: Fixed-point arithmetic library
Date 2012-02-23 23:21 +0100
Message-ID <9qnsf4Fv8fU1@mid.individual.net> (permalink)
References <alpine.DEB.2.00.1202222012550.5334@urchin.earth.li> <ji3ogh$i8r$1@news.albasani.net> <alpine.DEB.2.00.1202232046150.23797@urchin.earth.li>

Show all headers | View raw


On 02/23/2012 10:15 PM, Tom Anderson wrote:
> On Wed, 22 Feb 2012, Jan Burse wrote:
>
>> If a decimal scale suits you, you could use:
>>
>> http://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.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

"few" like in "a few millions per second"?

> 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.

How long is that benchmark ago?  JVMs and standard library have changed 
quite a bit during past years so the performance issues might actually 
have gone by now.

If I would be the one responsible I'd do the measurements myself.  It's 
usually better to base such decisions on hard (and current) facts.  Your 
application obviously exists so you have a clear idea of the nature of 
operations you have to perform as well as the frequency of operations as 
well as the range of input data.  That should make it quite easy to 
build a benchmark which realistically reflects your business case.  You 
could separate the load driving from the used math implementation via 
interface (see minimalistic example below) so you can reuse the same 
tests for all the implementations you want to analyze (at least 
BigDecimal and what you built).

Kind regards

	robert


package clj.math;

/**
  * Abstraction of math impl.
  *
  * @param <T>
  *            type of math numbers
  * @author robert
  */
public interface Math<T> {

	/**
	 * Create a new number from int.
	 *
	 * @param i
	 *            an integer to be converted.
	 * @return a number object representing the int.
	 */
	T create(int i);

	/**
	 * Create a new number from String.
	 *
	 * @param s
	 *            input string, must be a decimal representation of a number.
	 * @return a number object representing the string.
	 */
	T create(String s);

	/**
	 * Addition of two numbers.
	 *
	 * @param a
	 *            a number
	 * @param b
	 *            a number
	 * @return a + b
	 */
	T plus(T a, T b);

	/**
	 * Multiplication of two numbers.
	 *
	 * @param a
	 *            a number
	 * @param b
	 *            a number
	 * @return a * b
	 */
	T mult(T a, T b);
}

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Fixed-point arithmetic library Tom Anderson <twic@urchin.earth.li> - 2012-02-22 21:39 +0000
  Re: Fixed-point arithmetic library Jan Burse <janburse@fastmail.fm> - 2012-02-22 22:59 +0100
    Re: Fixed-point arithmetic library Tom Anderson <twic@urchin.earth.li> - 2012-02-23 21:15 +0000
      Re: Fixed-point arithmetic library markspace <-@.> - 2012-02-23 13:53 -0800
      Re: Fixed-point arithmetic library Robert Klemme <shortcutter@googlemail.com> - 2012-02-23 23:21 +0100
      Re: Fixed-point arithmetic library Jan Burse <janburse@fastmail.fm> - 2012-02-24 00:02 +0100
  Re: Fixed-point arithmetic library Robert Klemme <shortcutter@googlemail.com> - 2012-02-22 23:13 +0100
    Re: Fixed-point arithmetic library Gene Wirchenko <genew@ocis.net> - 2012-02-22 14:59 -0800
      Re: Fixed-point arithmetic library Martin Gregorie <martin@address-in-sig.invalid> - 2012-02-23 01:05 +0000
        Re: Fixed-point arithmetic library Tom Anderson <twic@urchin.earth.li> - 2012-02-23 21:21 +0000
          Re: Fixed-point arithmetic library Gene Wirchenko <genew@ocis.net> - 2012-02-23 13:49 -0800
      Re: Fixed-point arithmetic library Tom Anderson <twic@urchin.earth.li> - 2012-02-23 21:16 +0000
        Re: Fixed-point arithmetic library Gene Wirchenko <genew@ocis.net> - 2012-02-23 14:03 -0800
          Re: Fixed-point arithmetic library Lew <noone@lewscanon.com> - 2012-02-23 14:42 -0800
            Re: Fixed-point arithmetic library Gene Wirchenko <genew@ocis.net> - 2012-02-23 15:08 -0800
        Re: Fixed-point arithmetic library Martin Gregorie <martin@address-in-sig.invalid> - 2012-02-23 23:05 +0000
    Re: Fixed-point arithmetic library glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2012-02-27 00:59 +0000
      Re: Fixed-point arithmetic library Arne Vajhøj <arne@vajhoej.dk> - 2012-02-26 20:50 -0500
        Re: Fixed-point arithmetic library Robert Klemme <shortcutter@googlemail.com> - 2012-02-27 07:32 +0100
          Re: Fixed-point arithmetic library Jan Burse <janburse@fastmail.fm> - 2012-02-27 13:46 +0100
  Re: Fixed-point arithmetic library Roedy Green <see_website@mindprod.com.invalid> - 2012-02-24 16:26 -0800

csiph-web