3

This may strike as particularly odd but I must compile several new code against GCJ; that doesn't support Java's BigDecimal.

What I'm looking for is an alternative to java.math.BigDecimal.

Can anyone point me in the right direction?

Thanks!

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
Frankie
  • 24,627
  • 10
  • 79
  • 121
  • 1
    What exactly is GCJ? If it doesn't support some parts of standard Java API, how can you be sure it'll support your new library? – Nikita Rybak Jan 25 '11 at 20:43
  • Are you sure that gcj doesn't support parts of the *standard* Java API? This sounds more like a library issue that an issue with gcj. – Vivin Paliath Jan 25 '11 at 20:45
  • 1
    @Nikita GCJ is the Gnu Compiler for Java - http://gcc.gnu.org/java/ - it's actually a pain in the ass and I really don't know if it will support or not the new library, but if it's totally encapsulated (the new library) and only uses Java 1.4 syntax I'll probably be safe. – Frankie Jan 25 '11 at 20:46
  • @Frankie what version of gcj? – Vivin Paliath Jan 25 '11 at 20:46
  • @Frankie what happens when you try to compile a program that uses `java.math.BigDecimal`? – Vivin Paliath Jan 25 '11 at 20:49
  • @Vivin GCJ blows on some methods it doesn't support yet (GCJ has a semi-implementation of BigDecimal). On my particular case: `error: class 'java.math.BigDecimal' has no method named 'setScale' matching signature '(ILjava/math/RoundingMode;)Ljava/math/BigDecimal;'` thks – Frankie Jan 25 '11 at 20:53
  • Have you tried taking the code for BigDecimal/BigInteger from Java 6 and compiling it with GCJ? – Peter Lawrey Jan 25 '11 at 21:01
  • @Peter, actually yes, did try that prior to asking. All went kabum! :) Vivin's answer works great! – Frankie Jan 25 '11 at 21:13
  • 1
    Taking code out of Apache Harmony might be better from a licensing perspective. – Tom Hawtin - tackline Jan 25 '11 at 21:29

1 Answers1

3

It looks like gcj is compiling against JDK 1.4.2, which only provides setScale(int scale, int roundingMode) and setScale(int scale).

The code you're trying to compile seems to have been written for JDK 1.5.0 and above. In JDK 1.5.0, you get setScale(int newScale, RoundingMode roundingMode) in addition to the other two.

You can see if there is an update to gcj that lets it use 1.5. From looking at the gcj website, I don't see this as the case. It says that the current version "supports most of the 1.4 libraries plus some 1.5 additions."

Your other option is to rewrite the code so that calls to setScale(int newScale, RoundingMode roundingMode) are replaced by setScale(int scale, int roundingMode). In 1.5.0, instead of specifing an integer value for roundingMode (using the static ints in BigDecimal), you can specify it using the RoundingMode enum (the older method is still maintained for backwards compatibility).

So in your code, instead of RoundingMode.CEILING, you would use BigDecimal.ROUND_CEILING.

Vivin Paliath
  • 94,126
  • 40
  • 223
  • 295