Comments (4)
Hi Mikhail,
Thanks for reporting this. This Math Utility was originally contributed by Frans Lelieveld, so I'm not very familiar with its implementation. Would you be able (and willing) to look into this issue and see whether this is actually a bug in the code, or for example a rounding issue? Your input is a very long number, and the scaled difference seems very small compared to the very big number you put in, so I wouldn't be surprised if this issue is caused by rounding.
from jorlib.
from jorlib.
Joris, I found that the method gives wrong answer for the number 4 * 10^74 + 1
with rounding mode UP. The square root of this number exceeds 2 * 10^37
, so correct UP rounding with 1 digit precision should be the number 3 * 10^37
. But
BigDecimal number = new BigDecimal(new BigInteger("4"), -74).add(BigDecimal.ONE);
mathContext = new MathContext(1, RoundingMode.UP);
System.out.println(MathUtil.sqrt(number, mathContext).toPlainString());
produces 2E+37
.
from jorlib.
Hm I agree with your example. It seems that this error occurs with very
tiny numbers. Given that you were able to study the book which was used to
implement this algorithm, would you be able to spot the implementation
issue? The book refers to an implementation itsqrt.cc, which you can find
on the publisher's website:
http://extras.springer.com/2001/978-3-642-56735-3/hfloat/hfloat/src/hf/itsqrt.cc
The first line states: "#warning 'sqrt_iteration() is experimental (loss
of precision !)'". So I'm not surprised that you encounter precision errors
with such small numbers. Here's another implementation:
https://github.com/rizar/matrix/blob/master/src/com/github/rizar/bigdecimalmath/BigDecimalMath.java
Does this one have similar issues?
I'm happy to help you out wherever I can, but I have very little knowledge
about this specific domain...
Joris
On Fri, Apr 22, 2016 at 9:40 AM, Mikhail Zvagelsky <[email protected]
wrote:
Joris, I found that the method gives wrong answer for the number 4 *
10^74 + 1 with rounding mode UP. The square root of this number exceeds 2
- 10^37, so correct UP rounding with 1 digit precision should be the
number 3 * 10^37. ButBigDecimal number = new BigDecimal(new BigInteger("4"),
-74).add(BigDecimal.ONE);
mathContext = new MathContext(1, RoundingMode.UP);
System.out.println(MathUtil.sqrt(number, mathContext).toPlainString());produces 2E+37.
—
You are receiving this because you commented.
Reply to this email directly or view it on GitHub
https://github.com/jkinable/jorlib/issues/4#issuecomment-213431613
from jorlib.
Related Issues (16)
- TODO: Change TSPLibTour class
- TODO: Make BranchAndPrice multi threaded HOT 1
- TODO: Write GUI depicting the Branch-And-Price solve process
- Manual outdated on ColGen constructor HOT 2
- Interaction between AbstractMaster and Master may lead to subtle bugs HOT 4
- Compile error in Eclipse due to an incomplete looking exclude HOT 2
- Raw use of parameterized classes HOT 10
- Implementation Column Manager HOT 6
- Change of package names makes that all code needs to switch package names HOT 3
- Branch and Price does not handle infeasibility
- Objective does not need to be integral when solution is integral
- Reflection may fail in constructing pricing problem solver HOT 2
- Unable to use a model specific Configuration HOT 3
- Documentation does not clearly specify that columns are added to master problem
- Maven build failing HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jorlib.