Re: Arithmetics
From: Phlip (phlip_cpp_at_yahoo.com)
Date: 02/15/04
- Next message: A. G. McDowell: "Re: Rational Rose SUCKS!"
- Previous message: Steven Wurster: "Re: Iterators redux"
- Next in thread: Avner Ben: "Re: Arithmetics"
- Reply: Avner Ben: "Re: Arithmetics"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 15 Feb 2004 20:17:03 GMT
[cross-posted to a newsgroup that had a discussion about this exact issue
recently]
Milan Čermák wrote:
> I'm about to write an arithmetics object library. It should contain
> classes like ShortInteger (for 32-bit longs), Double and Float as
> standard numeric type wrappers and LongInteger (really long numbers, not
> only 64-bit) and Fraction (to express high precission).
> All these classes may inherit from abstract class Number.
Why?
If they inherit, what virtual method do they override?
If you mean that clients of Number can accept a Number & and use it, without
knowing what derived type it is, can you show an example of what you want
such a client to look like?
> I got stuck on following point. I'm not sure how to implement basic
> arithmetic operations. What the result type should be? (I don't mean
> method return type, but specific operation result type, ie. 1.0 + 1.0 =
> <double> 2.0.)
Double + Double = Fraction, because the result could overflow Double's
range.
Assuming a Fraction is two LongIntegers - a numerator and denominator -
hence it can store any rational.
Now, how to store any irrational?
> And one more question. If I put the code into a library, it be possible
> to extend it? For example some one may want to implement Complex.
What ultimate problem are you trying to solve? Is the problem "I don't have
an arithmetics object library"?
If you want to solve math problems, which ones? If you try to write a
library that "could" solve any of them (including the ones that have no
numbers), you will only get stuck.
--
Phlip
http://www.xpsd.org/cgi-bin/wiki?TestFirstUserInterfaces
- Next message: A. G. McDowell: "Re: Rational Rose SUCKS!"
- Previous message: Steven Wurster: "Re: Iterators redux"
- Next in thread: Avner Ben: "Re: Arithmetics"
- Reply: Avner Ben: "Re: Arithmetics"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]