Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

math.log estimation broken for BigDecimal (scala 2.13) #840

Open
xmelko91 opened this issue Sep 27, 2019 · 3 comments
Open

math.log estimation broken for BigDecimal (scala 2.13) #840

xmelko91 opened this issue Sep 27, 2019 · 3 comments

Comments

@xmelko91
Copy link

xmelko91 commented Sep 27, 2019

Trying to estimate log(BigDecimal) starts infinite loop for some random BigDecimals values, trying to test it and get this:

timer.start()
  for(_ <- 1 to 100){
    val bd = BigDecimal(math.random() * 100)
    print(s"for BigDecimal $bd")
    println(s" result is ${ln(bd)}")
    timer.restartTimer
  }

output:

for BigDecimal 95.43783506046007 result is 4.5584750937568150091505279932085940
for BigDecimal 65.74758834870731 result is 4.1858229912780658998029987138361140
for BigDecimal 19.975121517921245 result is 2.9944875751342717477239494914685500
for BigDecimal 35.87874081671405 result is 3.5801449422802959968367744428563220
for BigDecimal 57.00977196205218
1
2
3
4
5...

With Double values it works perfectly.

@denisrosset
Copy link
Collaborator

@xmelko91 Thanks for the bug report. I can't fix the issue right now.

In general, I think we need to be careful with BigDecimal support in Spire, due to the use of MathContext which does not fit exactly with the principles adopted by Spire.

You may want to have a look at https://github.com/eobermuhlner/big-math

(Also for us, for future reference when fixing this)

@armanbilge
Copy link
Member

See also report in #1051.

@djx314
Copy link

djx314 commented Jan 25, 2023

Since #1051 is closed, copy the suggestion here.

@armanbilge
spire is a type level math repo. So I think we can make log(Int, Int) different from log(double, double).
In BigDecimal 1 means 1.00000000 and in Int 1 just means 1. This in scala is easy and it's a worthwhile job.

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

No branches or pull requests

4 participants