Giter VIP home page Giter VIP logo

Comments (11)

non avatar non commented on August 18, 2024

I think those implicits will probably need to be opt-in, since many users may not want this behavior by default. But it's a good point. We can certainly give Number implicits to go from all the other number types to Number.

from spire.

dlrodriguez avatar dlrodriguez commented on August 18, 2024

Hi Erik and others. Hope you don't mind me throwing my 2 cents in. I'm attempting to build a parametric geometry modeler using spire, because one nice feature would the ability to use doubles, complex numbers, or even hyper dual numbers. Therefore, I am writing all my methods using the spire version of Numeric. I have noticed I have to always use the fromDouble() method to work with literal doubles, however. Are there some implicits I'm failing to import? Would be nice to not have to write:

val y = x * fromDouble(2.0) // wish it could be x * 2.0 and get y:Numeric[Double]

fyi, x is a Numeric[Double]

just my thoughts and yes I am new to Scala and spire...but learning fast. thanks for your contributions. hope I can help in some way someday soon.

from spire.

non avatar non commented on August 18, 2024

Hm. I guess the best way to accomplish all of this would be to have some optional packages that can be imported to achieve this. These behaviors are probably not great to have on all-the-time although I totally see why they would be useful.

I'm still working on some of the other changes to Number. I'll try to push those tonight so you all can give some feedback.

from spire.

non avatar non commented on August 18, 2024

This should be working in the 2.10.0 branch. (For Number). No extra imports should be required besides spire.math._.

dlrodriguez, can you open a new ticket for your issue? I will look into it but I'm going to close this one since it is working for me now.

from spire.

benibela avatar benibela commented on August 18, 2024

It seems to work only in one direction:

scala> Number(1) + SafeLong(7)
res5: spire.math.Number = IntNumber(8)

scala> SafeLong(7) + Number(1)
:48: error: could not find implicit value for evidence parameter of type spire.algebra.AdditiveMonoid[scala.math.ScalaNumericConversions with scala.math.Ordered[_ >: spire.math.SafeLong with spire.math.Number <: scala.math.ScalaNumericConversions with scala.math.Ordered[_ >: spire.math.SafeLong with spire.math.Number <: scala.math.ScalaNumericConversions]]]
SafeLong(7) + Number(1)

from spire.

non avatar non commented on August 18, 2024

Hm, I thought I tested that. Time to work on it some more...

from spire.

non avatar non commented on August 18, 2024

This should be fixed again.

from spire.

benibela avatar benibela commented on August 18, 2024

But it gets the wrong type, when the safelong is left:

scala> Number(1) + SafeLong(7)
res12: spire.math.Number = IntNumber(8)

scala> SafeLong(7) + Number(1)
res9: spire.math.Number = FloatNumber(8.0)

On 01/06/2013 01:47 AM, Erik Osheim wrote:

This should be fixed again.


Reply to this email directly or view it on GitHub
#45 (comment).

from spire.

non avatar non commented on August 18, 2024

Yeah, that is going to be a little more difficult to fix. All I can say is that implicit conversions are annoying and it's really easy to hit ambiguities. Right now we're just converting to Double in that position so that all conversions pass through the same implicit and we avoid ambiguity.

I don't love it either, but I can't promise it will be fixed soon. Given that Scala has special built-in support for numeric coercisions (which only works for the built-in types) I can't promise that all of Spire's types are going to magically coerce quite as well as we'd like.

from spire.

non avatar non commented on August 18, 2024

Actually nevermind there probably is an easier way to fix this.

from spire.

non avatar non commented on August 18, 2024

This should be improved now. Thanks for your feedback!

from spire.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.