Hi Hugo,
If you 'import spire.implicits._' that will provide a bunch of new
methods on Double/BigDecimal (using the relevant NRoot[_] instance)
which will allow you to take roots and such.
import spire.algebra.Trig
import spire.implicits._
(3.0).nroot(3) // cube-root of 3
// 1.4422495703074083
BigDecimal(3).nroot(3)
// 1.442249570307408382321638310780110
Trig[Double].sin(33.333)
// 0.9406427616458263
Trig[BigDecimal].sin(BigDecimal("33.333"))
// 0.9406427616458257562817995457628267102
It sounds like you didn't have that import set up.
You can use spire.math.Real to wrap Rational and support roots,
trigonometry, etc. That class is the successor to the CReal type you
mentioned. Here's an example:
import spire.math._
val rat: Rational = Rational(1, 3) // one third
val x: Real = Real(rat).sqrt
x.toRational
// 100588603464850855725768518207408495724057/174224571863520493293247799005065324265472
x.toRational(80)
// 174493411846198778282783/302231454903657293676544
x.toRational(40)
// 634803334273/1099511627776
You will have to choose how much precision you want the resulting
rational to be. The values 40, and 80, refer to the precision of the
denominator, i.e. 2^40 or 2^80.
In a follow-up email I can try to explain how to build a custom type
which supports NRoot[_] and Trig[_] but first I wanted to make sure I
answered your basic questions about using Rational. Let me know if
this makes sense and works for you.
Thanks,
-- Erik
> --
> You received this message because you are subscribed to the Google Groups "Typelevel Users & Development List" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
typelevel+...@googlegroups.com.
> To post to this group, send email to
type...@googlegroups.com.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/typelevel/e7637136-e7cd-48b9-8e13-c8490ef0c318%40googlegroups.com.
> For more options, visit
https://groups.google.com/d/optout.