Forums | Admin

Discussion Forums: open-discussion

Start New Thread Start New Thread

 

By: Karl Brodowsky
RE: how much functionality for LongDecimal?? [ reply ]  
2006-03-03 19:56
Thank you for the input. I have done a lot of research on functionality and algorithms, but I did not find this one. The GNU-multiprecision-library is also a good place to look at.

The problem is, we have four different variants of high precision arithmetic:
- long integers (natively supported by Ruby)
- rational numbers (require "rational")
- arbitrary precision floating point (require "bigdecimal")
- arbitrary precision fixed point (the new LongDecimal)

NTL would be useful for what BigDecimal is covering in Ruby. But I will sure have a look at NTL. There could be some overlap with "bigdecimal", especially when it comes to functionalities like log and exp and **, of whom I am not entirely sure, if they belong at all into LongDecimal, but I tend to add them anyway.

I just want to make clear, that it is really very important to choose the right one of these four.
They are *not* interchangeable, at least not easily.

When exact calculations expressable with integers
are needed, use integers.

When exact calculations are needed, but integers do not suffice, Rational is probably the right way to go.

When numeric calculations for physics, engeneering etc. are needed, Float or BigDecimal (which is actually some kind of long-float) are needed. Or a mixture. Choose well between these.

For finance applications where exactness to a certain number of digits and a certain well defined set of rounding rules is required, LongDecimal is the way to go, if you trust it already. It is still "pre-alpha", but should already be somewhat usable and it should be possible to fix bugs that appear during the development of an application that depends on LongDecimal.

I must admit, that LongDecimal is relatively simple to develop. It depends internally mostly on integer arithmetic, but there are some additional aspects about rounding and about division, that did make it a little bit challenging anyway.

I tried to avoid going to implementation in C or Assembler, because I think that this kind of optimization is mostly needed and provided for the underlying integer arithmetic, which I assume is where calculations using LongDecimal will internally spend most of the time.

By: Richard Graham
RE: how much functionality for LongDecimal?? [ reply ]  
2006-03-03 19:35
Not sure if you'll consider this helpful, but the C++ NTL library by Victor Shoup is top notch and has an arbitary precision floating point number class that you may want to look at to compare functionality and/or lift algorithms, etc.

http://www.shoup.net/ntl/
http://www.shoup.net/ntl/doc/RR.txt

By: Karl Brodowsky
how much functionality does LongDecimal need? [ reply ]  
2006-02-20 09:09
LongDecimal is now pretty complete in terms of the functionality that is needed for its core purposes.

The question is how much sense it would make to add stuff that exists for Float, like functions sin cos tan log exp sqrt etc. They don't really belong here so urgently, because the stuff where you need them, is better done with BigDecimal (floating point with arbitrary precision) and not with LongDecimal (fixed poind with arbitrary precision). But it could off course be done.
exp and tan are kind of problematic, because they tend to need any number of digits before the decimal point.

Any comments?