• Post Reply Bookmark Topic Watch Topic
  • New Topic

My own Java 'Real' number class  RSS feed

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am writing a Java 'Real' number class, that runs in a similar way to Java's BigDecimal class, so it handles basic number operations, add, subtract etc.
The instance variable 'x' will represent the real number itself once it's value has been passed via a parameter in the class constructor.

My problem is, that this variable 'x' needs to be of either BigDecimal, or of another extended arithmetic type, DoubleDouble.  So, my class will be along the lines of:-

public class Real
{

    BigDecimal OR DoubleDouble x;

    public Real(String x)
    {
        this.x = ...
    }
}


I've thought about using an interface, but how to do that with BigDecimal? Any other options?

Thanks
Jeremy
 
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why? What is DoubleDouble, and why can your Real class be composed of either of two other types?
 
Jeremy Watts
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DoubleDouble is another class, similar to BigDecimal, it is itself an extended precision number class, but is faster than BigDecimal.

There is something that I neglected to include in my original post. There is another static instance variable called NumericalMode, which can be set in one of two states, either
BIGDECIMAL or DOUBLEDOUBLE, and so I require that 'x' instantiates either a new BigDecimal object or a DoubleDouble accordingly.
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can take this like basement for you, because I didn't understand exactly your intention


 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!