0

I have a series of probabilities p1, p2, p3, p4, and I need to transform each one to a logarithmic scale to make comparisons. This is easy to do with int datatypes, but I am using BigDecimal because I need precision, and I can't find a way to do it.

The code in Logarithm of a BigDecimal is giving me an error. Specifically, the code hasn't defined the method exp(). The response is marked up, but there are comments that concur that it is incomplete.

The undefined method:

BigDecimal eToX = exp(x, sp1);

Community
  • 1
  • 1
traderjosh
  • 321
  • 5
  • 16
  • No it's not. That code is incomplete and I have tried nearly everybody's code in that post – traderjosh Aug 29 '16 at 08:29
  • That code works, I tested it myself multiple times in the past. Maybe you could ask a new question with exactly what is wrong with your code? – Tunaki Aug 29 '16 at 08:34
  • this answer seems to work http://stackoverflow.com/a/9125512/2310289 – Scary Wombat Aug 29 '16 at 08:36
  • I can edit this post if you remove the duplicate tag. I just tried to make a new post but now I have to wait 90 minutes – traderjosh Aug 29 '16 at 08:40
  • Wombat, I also tried that, but the method parameter takes in a BigInteger, not a BigDecimal. I am passing in probabilities of BigDecimal type. – traderjosh Aug 29 '16 at 08:44
  • Do you really need more than 15 digits of precision? You cant measure much that accurate in real life. – Peter Lawrey Aug 29 '16 at 10:08
  • @Joshua: do you need the logarithm (and, if so, which one -- natural or base 10) or the opposite, `exp(x, y)`? Some languages, if they write `log(x)` actually provide `ln(x)`. In math, `log` usually means the base-10 logarithm and `ln` the logarithm to the base of `e`. – Rudy Velthuis Aug 29 '16 at 10:31
  • Internally, a BigDecimal is a "scaled" BigInteger. If you have the natural or base-10 logarithm of the BigInteger (the `unscaledValue` of the BigDecimal), you only have to **subtract** the natural or base-10 logarithm of `10` multiplied by the `scale` of the BigDecimal. – Rudy Velthuis Aug 29 '16 at 10:35
  • 1
    In other words, `log(myBigDecimal)` equals, in pseudocode, `StackOverflowAnswer.log(myBigDecimal.unscaledValue()) - Math.log(10) * myBigDecimal.scale();`. – Rudy Velthuis Aug 29 '16 at 10:38
  • @PeterLawrey: People who use `BigDecimal` usually want that extra precision. That is most likely the reason why they use it. – Rudy Velthuis Aug 29 '16 at 16:47
  • @Joshua: OK, now I see what you mean: in the `LnNewton()` function, the "duplicate" uses a function `exp()` which is not shown and which probably only appears in the book mentioned. This makes that code pretty useless for everyone else and it does not answer your question. ***In other words, the "duplicate" is useless*** and should never have been upvoted, as it is not complete and does not answer that other question either. I voted to reopen your question. – Rudy Velthuis Aug 29 '16 at 18:08
  • @Tunaki: see my latest comment to Joshua: **the answer in the duplicate is useless to anyone who does not have the book mentioned** (and they will already have that answer anyway), since it uses a function (`exp(BigDecimal)`) which is not shown and which does not exist in the JDK either. Please consider reopening the question. – Rudy Velthuis Aug 29 '16 at 18:15
  • @RudyVelthuis I see your point but the questions _are_ definitely duplicates. One could also post a new correct and full answer to this linked question. There is no need to have multiple answers to the same question at multiple places. It only confuses readers. (I'll note that this isn't the only answer to the question, and I don't know why everyone focuses on it.). Feel free to invite me to chat so as not to post too many off-topic comments here. – Tunaki Aug 29 '16 at 18:20
  • @Tunaki: OK, that is possible too, but people will probably only see the much upvoted (but useless) answer there. It does not answer that nor this question. – Rudy Velthuis Aug 29 '16 at 18:24
  • @RudyVelthuis Yes, the matter [was discussed on Meta before](http://meta.stackoverflow.com/questions/295866/what-can-i-do-when-a-wrong-answer-to-my-question-is-massively-upvoted), although not specific to this question. [See also this other post](http://meta.stackoverflow.com/questions/255198/how-to-handle-historical-highly-upvoted-but-completely-incorrect-answers). Let's hope that, in time, a useful answer will come at the top. Sometimes [it works](http://meta.stackoverflow.com/questions/308950/what-to-do-if-voting-based-qa-does-not-work-at-all). – Tunaki Aug 29 '16 at 18:27
  • @Tunaki: thanks for the link. – Rudy Velthuis Aug 29 '16 at 19:26
  • I created a new post http://stackoverflow.com/questions/39236454/the-answer-for-logarithm-of-a-bigdecimal-type-is-incomplete Please don't mark it as a duplicate, as it's effecting my ability to make new posts. You should read the content of the post and the other answers given before downvoting. – traderjosh Aug 30 '16 at 20:23

0 Answers0