Skip to content
This repository has been archived by the owner on May 12, 2019. It is now read-only.

Sense of Decimal class? #50

Closed
ElMoe opened this issue Nov 16, 2015 · 4 comments
Closed

Sense of Decimal class? #50

ElMoe opened this issue Nov 16, 2015 · 4 comments
Labels

Comments

@ElMoe
Copy link
Contributor

ElMoe commented Nov 16, 2015

I don't understand the purpose of the Decimal class: what is the benefit of using decimal numbers instead of timeseries data?

@mdeverdelhan
Copy link
Owner

The Decimal type is the way I found to represent the numbers in ta4j. Originally we were using the double primitive type, but it resulted in huge approximations in calculations over time. See also:

Now (i.e. it may change) Decimal delegates all the operations to BigDecimal, so it is based on BigDecimal's concepts (http://docs.oracle.com/javase/8/docs/api/java/math/BigDecimal.html).

Feel free to update the wiki with explications about that if you think it's unclear.

@ElMoe
Copy link
Contributor Author

ElMoe commented Nov 21, 2015

Thank for the introductory links to the Decimal topic!
You write that Decimal is somehow similar to BigDecimal. I encounter some difficulties when i try BigDecimal synax on Decimal, e.g.:
For BigDecimal it's: BigDecimal b = new BigDecimal("2.0");
For Decimal it's: Decimal b = Decimal.valueOf("2.0");

Two questions:
1.) What is there a reason that Decimal usages differ from BigDecimal?
2.) Is it possible to simply cast a BigDecimal simply into Decimal?

I'll try to put an introduction about Decimal into the wiki when i have basic understanding of the topic.

@mdeverdelhan
Copy link
Owner

1.) What is there a reason that Decimal usages differ from BigDecimal?

I chose to simplify (at least according to me) the management of the numbers in ta4j. BigDecimal comes with a bunch of features I don't use (Math contexts, management of VERY big numbers, divide-by-zero exception, ...).

2.) Is it possible to simply cast a BigDecimal simply into Decimal?

It would be possible if Decimal was extending BigDecimal. If so, I would have inherit all the features I mentioned above, and I plan (some day) to refactor this class to avoid using BigDecimal.

@ElMoe
Copy link
Contributor Author

ElMoe commented Nov 25, 2015

Okay, thank you for the explications.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants