Java should provide exact real arithmetics

Andreas Andreakis andreas.andreakis at googlemail.com
Wed Dec 12 11:00:21 UTC 2007


Hi,


sorry everybody, but I copy-pasted a wrong code snipped in my original post.
Because most of the time is spend in string concatination and printing the
output of each calculation loop.

this is a correct version:

        int loops = 100;

        for(int i = 0; i<loops; i++){
            BigDecimal number = new BigDecimal("0.123");
            long time = System.currentTimeMillis();

            for(int j = 0; j<i; j++){
                number = number.pow(2);
            }

            long requiredTime = System.currentTimeMillis() - time;
            System.out.println("length: "+number.toPlainString().length()+",
time: "+requiredTime+" ms");
        }


@ Roman,
thank you for the link. I´ve used apfloat before, but I experienced overflow
issues. Also the project does not seem to be developed actively.

JNI is not an option in my point of view.


kind regards,
Andreas



On Dec 12, 2007 11:01 AM, Roman Kennke <roman at kennke.org> wrote:

> Hi there,
>
> <snip>
>
> > Currently, there exist much better solutions than BigDecimal,
> > unfortunately not from the Java space. For instance GMP
> > ( http://gmplib.org/) is considered as one of the state of the art
> > libraries in the area of precision arithmetics. And several libraries
> > extent GMP such as the popular iRRAM project
> > (http://www.informatik.uni-trier.de/iRRAM/).
> >
> > Check out the following page in order to get an idea how performable
> > GMP is: http://gmplib.org/pi-with-gmp.html
> >
> > it demonstrates the calculation of pi with many digits.
> >
> >
> > I´m asking myself why there is nothing comparable for the java
> > platfom.
>
> Have you tried:
> http://www.apfloat.org/
>
> Not everything has to be in the core platform IMO (I think it's already
> much too bloated). Or maybe it could be considered to write a JNI-Layer
> on top of GMP?
>
> Cheers, Roman
> --
> http://kennke.org/blog/
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/core-libs-dev/attachments/20071212/9f427f30/attachment.html>


More information about the core-libs-dev mailing list