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 can not calculate some result. #1051

Closed
djx314 opened this issue Aug 7, 2021 · 3 comments
Closed

math.log can not calculate some result. #1051

djx314 opened this issue Aug 7, 2021 · 3 comments

Comments

@djx314
Copy link

djx314 commented Aug 7, 2021

import spire.implicits._
import spire.math._
val list1 = for {
  i1 <- LazyList.from(2 to 40)
  i2 <- LazyList.from(1 to 4000)
} yield {
  val num1 = LongContext(i1, i2).log
  val num2 = log(i2, i1)
  (i1, i2, num1, num2)
}

val result = list1.filter(s => !(s._3 == s._4.toInt))

result.to(List).map(s => println(s"log(${s._1}, ${s._2}), number left in spire: ${s._4}, number right: ${s._3}"))

that report

log(3, 243), number left in spire: 4.999999999999999, number right: 5
log(10, 1000), number left in spire: 2.9999999999999996, number right: 3

Java's log has the same problem. I don't know if it's expected behavior.
And I use

println(log(BigDecimal(243, MathContext.DECIMAL32), 3))
println(log(BigDecimal(1000, MathContext.DECIMAL32), 10))

the application can not stop.

@kschwarz1116
Copy link
Contributor

Possible dupe of #840. They're both non-terminating performance issues around log of BigDecimal.

@armanbilge
Copy link
Member

Agree. Tracked in #840.

@armanbilge armanbilge closed this as not planned Won't fix, can't repro, duplicate, stale May 27, 2022
@djx314
Copy link
Author

djx314 commented Nov 30, 2022

@armanbilge Reopen for new idea.
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

3 participants